Hello everyone, I've been working a couple of days on this school project, here the issue I stepped into:
I have 3 classes that inherit some traits from an User parent class. The three sub-classes are meant to add some specific functions and attributes.
1 2 3 4 5 6 7 8 9 10 11
class User {
protected:
string _username, _address;
Date _date;
public:
User();
User(const User &to_copy);
//Getters
//Setters
};
1 2 3 4 5 6 7 8 9
class StandardUsr : public User {
private:
string _name, _surname;
char _gender;
public:
//Getters
//Setters
};
I then need to fit a bunch of instances of the three different sub-classes in some container (map), and to use them when needed. I instance a map<String,User> and fit them into it.
What happens is that the insertion "slices off" everything but the attributes/methods belonging to the parent User class.
I also tried to use User* pointers instead of User in the map, but when doing so, I can only use User's public methods.
Sorry, I wasn't clear enough.I know i can only access public. What I mean is I cannot use methods of StandardUsr, but only User's. Even if I cast the pointer (User*) to (StandardUsr*), StandardUsr's data are not shown.
I'm now doing some edit, because I actually use pointers, dynamic memory, everything in a Template Class, and I'm quite a newbie actually.
I might have done some unwanted cast of some sort,I'll double check and be right back!
Thank you for now!