Elements follow directly without alignment by default; #pragma pack(1) can enforce C++ style alignment.
Auxiliary members ('fillers') can be used for custom alignment.
Structures with string or dynamic array members get an implicit constructor.
Simple structures (no strings/dynamic arrays) can be freely copied and passed to DLLs.
Access members using the dot operator (.).
Classes
Use class keyword.
Default access specifier is private.
Objects have a virtual function table by default.
Support the new operator.
Can inherit only from classes.
Can have explicit constructors and destructors.
If a constructor is explicit, initialization via sequence is impossible.
Constructors and Destructors
Constructor: Special function called on object creation, used for initialization. Name matches class name, no return type.
Destructor: Special function called on object destruction (~ClassName()).
If a class has strings or dynamic arrays, they are initialized/de-initialized regardless of constructor/destructor presence.
Multiple constructors (default, parametric) are allowed.
If no constructor is declared, the compiler generates a default constructor.
If a user-defined constructor exists, the default constructor is NOT generated.
Constructors can use initialization lists.
Destructors are always virtual.
Defining Class Methods
Methods can be defined inside or outside the class declaration.
Outside definition uses the scope resolution operator (::).
Access Modifiers
public: Accessible from anywhere.
protected: Accessible within the class and derived classes.
private: Accessible only within the class.
Modifier 'final'
class ClassName final: Prohibits further inheritance.
Unions
Data type with multiple variables sharing the same memory area.
Allows interpreting the same bit sequence in different ways.
Declaration similar to structures, starts with union keyword.
Memory allocated for the largest member type.
Access members using the dot operator (.).
Cannot be involved in inheritance, cannot have static members.
Cannot contain: dynamic arrays, strings, pointers to objects/functions, class objects, structures with constructors/destructors, or structures with members from the above.
Can have constructors, destructors, and methods.
Default access is public.
Interfaces
Define specific functionality for classes to implement.
Cannot contain members, constructors, or destructors.
All methods are purely virtual.
Defined using the interface keyword.
Objects cannot be created without inheritance.
Can only be inherited from other interfaces and can be a parent for a class.