0
Why is this showing an error?
5 Antworten
+ 3
cout << obj.method()
-> obj.method()
Call obj.method() and don't use cout.
+ 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;
}
+ 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
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?



