Thread: C++ Classes, problem with function.
when run code through g++ following error. re-wrote code on advice of dwhitney , found i'm not sure how use features.
here's problem...
error: request member 'returnmodel' in 'ferrari' of non-class type 'car*'
i'm aware have following function defined within class.
returnmodel()
{
return (carmodel);
}
have defined ferrari within main()
car* ferrari = new car ( ...data here...)
entered code.
cout << ferrari.returnmodel()
, got above error, supply hint.
see if can put following use:
code:#include <string> #include <iostream> class car { public: ... std::string getmodel() const { return carmodel; } ... private: std::string carmodel; ... }; int main() { using namespace std; car* ferrari = new car("ferrari", 280, 250, 275000); cout << ferrari->getmodel() << endl; delete ferrari; }
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] C++ Classes, problem with function.
Ubuntu
Comments
Post a Comment