I need to be able to use a private class variable in several cout statements. I need to do something like this..
but that obviously gives me errors.Code:cout <<"Hello " <<Person.displayName() <<"how are you today" <<endl;
Here is the class, the code isn't perfect and I actually typed it out in wordpad. None of it has been compiled so please disreguard all the obvious errors.
Now, I can use it the way I want but I have to do it in a rather messy way.Code:class Persons { public: void setName(string); string getName(); void displayName(); private: string PersonName; }; void Person::setName(string name){ PersonName = Name; } string Person::getPName() { return PersonName; } void Person::displayPName() { cout <<getName(); }
Is there a better way to do this so I don't have to break up the cout statments?Code:cout <<"Hello "; Person.displayName(); cout <<" how are you today?" <<endl;



LinkBack URL
About LinkBacks



