"jalkadir" <ja******@gosonic.ca> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Let's say that I have this class:
class Parent{
private: char* str;
public: const char* getStr(){return str;}
};
And then I create a child class
class Child{
private: std::string str;
public: std::string& getStr(){return str;}
};
How do I call the Parent class method in a program, i.e.
int main(){
Child obj;
std::cout << obj.getStr() << std::endl;
return 0;
}
In the above example the method access would be the Child::getStr(),
but I would like to access the Parent::getStr(), how do I do that?
What problem are you having accessing memebrs of a Parent object? You
created a Child object and called a function from it. Why can't you just
create a Parent object and call a function on it, too? Did you try? If so,
what's that code, and what error or problem do you see?
(And by the way, is there some reason you're calling those Parent and Child?
Nothing in the code you've shown makes any connection between those two
classes. Did you intend for Child to be a derived class of Parent? Or is
the Parent class supposed to point to a list of its children (and
vice-versa)? Or were those just arbitrary names?)
-Howard