Why is this showing an error? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
29th Apr 2021, 2:19 AM
RuntimeERROR
RuntimeERROR - avatar
4 Respostas
+ 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