Sorry that this is not an Unreal-specific question, but just related to C++. Before recently starting to learn Unreal, I haven’t programmed in C++ for probably 15-20 years (mainly using C#, VB.NET, python, etc. in the meantime). I used to be fairly proficient in C++ way back then, but it seems that since that time a number of “standard” types were added to C++ to try to emulate some of nicer features of C# (garbage collection, “object” type, lists & collections, etc.). I’m trying to understand how some of these work.
Regarding the “any” type. As I understand it’s trying to be similar to the C# “object” base type functionality in a way that’s better than just using void*.
Based on the code snippet below, I have a few questions:
class c_class { public: int b;}; c_class d = *(new c_class()); d.b = 5; std::any a = d; std::any a2 = a; std::any_cast<c_class>(a2).b = 10;
Is the variable “a” storing a pointer to “d” or a copy of “d”? I believe it’s a pointer, but couldn’t find a clear answer to that.
When variable “a” is assigned to “a2”, do they both now refer to the same address? So when I cast a2 to “c_class” and set “b” field to 10, would it change the original instance “d” as well?
Regarding std::shared_ptr. My understanding is this pointer keeps track of references to the object it points to and deletes the object when all references are destroyed. What happens if, in addition to having a few shared_ptr’s point to this object, I also have some standard pointers point to it. Would the object get deleted when no more share_ptrs’ point to it, making any still existing standard pointers to it invalid?
Thanks a lot for your help. Again, sorry that these questions are not Unreal specific.