0

class and void function

I am a beginner, trying to learn how to use void function with a string type as parameter in a class. everything works fine but, when the program gets to this line cout<<yare.getname(d); it gives and error. Here is the entire program pls help. #include<iostream> #include<cstring> using namespace std; class Car { public: int maxspeed( int speed); void getname(string x); private: string name; }myCar, yare; int Car::maxspeed( int speed1) { return speed1; } void Car::getname(string x) { name=x; cout<<name; } int main(){ int c; string d=""; cout<<"Enter speed value"<<endl; cin>>c; cin>>d; cout<<myCar.maxspeed(c)<<endl; cout<<endl; cout<<yare.getname(d); }

8th Dec 2019, 7:36 PM
Mohamed
1 Odpowiedź
0
you don't need the cout in your last statement, your void function is doing the cout. simply remove it. yare.getname(d); // <----
8th Dec 2019, 9:36 PM
rodwynnejones
rodwynnejones - avatar