0
Whats wrong with foo(function)
#include <iostream> using namespace std; class my{ private: int data; public: my(int value) { data=value; cout<<data<<"constructor"<<endl; } ~my() { cout<<data<<"destructor"<<endl; } void foo() { cout<<"foo has been started" <<endl; my a(1); cout<<"foo has been finished"<<endl; } }; int main() { foo(); return 0; } Whats wrong with foo? https://code.sololearn.com/cVIwXli24M5K/?ref=app
1 Answer
+ 2
You need to create an instance of the class, in this example, it's ...'obj':
int main() {
my obj(49);
obj.foo();
return 0;
}