basic constructor cpp code example
Example 1: c++ struct constructor
struct TestStruct {
int id;
TestStruct() : id(42)
{
}
};
Example 2: c++ class constructor
class MyClass {
public:
MyClass(); // This is the constructor
private:
int someInt;
};
MyClass::MyClass(void) {
someInt = 1;
}