creating constructor in c++ code example
Example 1: cpp class constructor
class MyClass { // The class
public: // Access specifier
MyClass() { // Constructor
cout << "Hello World!";
}
};
Example 2: formats of constructor in c++
Line::Line( double len): length(len) {
cout << "Object is being created, length = " << len << endl;
}