Search code examples
c++struct

Structures in C++


I have some code in C with uses structures through out the code. I mostly use memset or memcpy to copy the data from/to buffer.

Wanted to know will this work in C++ ?. ' As per MSDN :

In C++, a structure is the same as a class except that its members are public by default.

So that means C++ compiler will insert the internals in to the structure object and memset or memcpy will not work as in C.

Also, is 'this' pointer applicable to structure also and is there any way i can stop the compiler from inserting anything C++ish in to my object ?


Solution

  • As long as your structures don't use any C++ constructs(virtualism etc), memcpy and memset will work on them even in C++.

    Also, is 'this' pointer applicable to structure?
    Yes, the this pointer is applicable to the structure as it is for a class.

    Is there any way i can stop the compiler from inserting anything C++ish in to my object ?
    The compiler won't unless you use any C++ constructs to your structure.