Why is this showing an error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
29th Apr 2021, 2:19 AM
RuntimeERROR
RuntimeERROR - avatar
4 Answers
+ 3
cout << obj.method() -> obj.method() Call obj.method() and don't use cout.
29th Apr 2021, 2:29 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
#include <iostream> using namespace std; class myClass{ public : int x=5; void method(){ cout <<"helllo"<<endl;} }; /*void myClass :: method(){ cout <<"jsnd"; }*/ int main() { myClass obj; cout <<obj.x; obj .method (); return 0; }
29th Apr 2021, 2:38 AM
Sâgærāvürï
Sâgærāvürï - avatar
+ 1
#include <iostream> using namespace std; class myClass{ public : int x=5; string method(){ return "hello";} }; /*void myClass :: method(){ cout <<"jsnd"; }*/ int main() { myClass obj; cout <<obj.x; cout << obj .method (); return 0; } You may try this as nikhil mentioned by changing the return type of your class method
30th Apr 2021, 7:09 AM
Mr.Dark
Mr.Dark - avatar
0
CarrieForle and also there are lot of error s popping when i was doing similar methods telling this is out of scope something like that,how could i address it?
29th Apr 2021, 2:39 AM
RuntimeERROR
RuntimeERROR - avatar