Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Default ctor, etc generated by compiler for structs?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="JohnQ, post: 2933372"] Different from an identical class? Conceptually how? Lately, I've been pondering, "when does a struct stop being a struct?". To me, that's when its not the same size as a C struct or not layed out the same. So obviously, when a virtual function gets added, then "a struct stops being a struct". I think I can add non-virtual member functions, non-virtual destructor and operators ad infinitum and the "struct will still be a struct" (right?). Even though some explicit syntax would make things more evident: struct A { int data; }; struct B { int data; B(int val){ data = val; } // OK, not virtual }; class StructWrapper { A a_struct; public: A(int val){ a_struct.data = val; } operator A&(){ return a_struct; } }; Where struct B can be used identically to struct A or StructWrapper (I hope!) as the layouts and sizes are the same (assume the operator is being used for StructWrapper when I say "can be used identically"). sizeof(A)==sizeof(B)==sizeof(StructWrapper) But a_struct in StructWrapper would have to be made public to guarantee the same layout as A and B? The equivalent of doing a memcpy of the class or struct (whether I used the right terminology or not I don't know... "bytewise" seems more appropriate). OK, so from what I gather, the compiler may or may not generate the functions/operators depending on the data members. Is it that if there is any non-POD data member, then the functions/operators get generated? Is it always the full set (?): default constructor, copy constructor, assignment operator, (destructor?). John [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Default ctor, etc generated by compiler for structs?
Top