0
Wy du v ned MyClass::MyClass() { } , f MyClass::MyClass() { } xcluded otput gvs er thnk u )
#include <iostream> using namespace std; class MyClass { public: MyClass(); void myPrint(); }; MyClass::MyClass() { } void MyClass::myPrint() { cout <<"Hello"<<endl; } int main() { MyClass obj; obj.myPrint(); }
2 Respuestas
+ 2
And what is a problem? In this code you have output hello 2 times, because constructor is invoke when you create obj(MyClass obj;) and second time you invoke mPrint() in code(obj.MyPrint)
+ 1
O, you need to realise function myPrint in class, not in construtor. This was your question? Why your code make error?