does a class need a constructor c++ code example
Example 1: c++ class constructor
class MyClass {
public:
MyClass(); // This is the constructor
private:
int someInt;
};
MyClass::MyClass(void) {
someInt = 1;
}
Example 2: cpp class constructor
class MyClass { // The class
public: // Access specifier
MyClass() { // Constructor
cout << "Hello World!";
}
};