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="Bo Persson, post: 2933840"] JohnQ wrote: :: :: I meant in memory. I still have the same question as when I :: started I guess: "when does a struct stop being a struct?". I think this is you basic problem! The standard says that certain structures are PODs. Everything else is not. 8.5.1 Aggregates "An aggregate is an array or a class (clause 9) with no user-declared constructors (12.1), no private or protected non-static data members (clause 11), no base classes (clause 10), and no virtual functions (10.3)." 9 Classes "A POD-struct is an aggregate class that has no non-static data members of type non-POD-struct, non-POD-union (or array of such types) or reference, and has no user-defined copy assignment operator and no user defined destructor." If you fullfill ALL the requirements, you are a POD. If you miss only one, you are not. :: And by :: that, I mean the guarantees I have for using it in a memcpy call :: for example. :: :: struct A :: { :: int val; :: }; :: :: class B :: { :: int val; :: :: B(int x){ val = x; } :: }; :: :: Is the following always trouble (?): :: :: memcpy(&A, &B, sizeof(A)); :: It is trouble in that the standard doesn't guarantee that it should work. It just might anyway, but we don't know. We cannot test it either, because the standard just doesn't say what should happen. So different things could happen different times, or with different compiler options, or definitely with different compilers. Bo Persson [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Default ctor, etc generated by compiler for structs?
Top