Tuesday, July 14, 2009

How to use string inside a user define class?

I need help using string inside a user define class.. this is for C++...


this is basically the question.. the class should have 3 private method: name(which is a string), cost (integer), quantity(integer);


i then need to make accessor modulator prototype... etc but my basic problem is passing the string n yes i did used #include%26lt;string%26gt;

How to use string inside a user define class?
Your question is incomplete, and I don't think you'll get a lot of helpful answers this way. What do you mean "passing the string n"? Data doesn't get passed to classes very obviously, it gets passed to member functions, though.
Reply:To make this class derive from string, use : private string after the class name.





To include a string as a private data member, use it after a private: label.





To access this data member, use *this-%26gt;name or just name from a member. Only friends can access name directly. You will need to provide wrapper functions for modifying and getting name from inside the class using public (for via objects) and protected (for via derived classes).





PS to Angus, n in this sentence is used as "and".


No comments:

Post a Comment