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="Victor Bazarov, post: 2933400"] What's "an identical class"? A class with the same order of its members, all declared public? No difference. Conceptually, every type has a destructor (or you can say that it does, since you can call it). The standard has s concept of "a pseudo-destructor call", which means that any type has at least a pseudo-destructor. In my book you can say that a concept of a destructor exists for every type. There is no code where the CPU is led to perform some actions when an object of a POD type is disposed of, yes. In that sense, a POD type does not have a d-tor. So, conceptually, yes, physically, no. Nope. If we agree to substitute the words "C struct" with "POD", then the Standard says that as soon as you add a user-defined c-tor, it's not a POD any more, so not all non-virtual member functions are "harmless" as far as POD-ness is concerned. Here, 'B' is not a POD class. You mean StructWrapper(int val) { a_struct.data = val; } , right? Nothing in the Standard says what the layouts are. We cannot rely on their being the same. That doesn't matter. Again, there is no way to "guarantee" what's not defined. There is no definition of a complete class layout in the Standard. Well, calling 'memcpy' upon copy-constructing an object is up to the implementation. There is no way to know exactly what they do with POD, most likely 'memcpy', or 'memmove', or some such. However, it would be safer to assume that "memberwise copy" is performed, which means that copy semantics for each member (provided they exist) are invoked. No, not always. For example, it's possible to copy-construct a reference, but it's not possible to assign one, so if your class has a data member that is a reference (it does make it non-POD, BTW), then the copy c-tor can (and will) be generated but the copy assignment op cannot (and will not) be. V [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Default ctor, etc generated by compiler for structs?
Top