Both of my classes: Parent and Child are the same (for now) and have the same constructor.
class Parent{
protected:
string name;
public:
Parent(string &n, vector <int> &v) {
/* read n and v into vars */
};
class Child : public Parent {
public:
Child(string &n, vector <int> &v) : Parent(n, v) {}
};
vector <int> val;
string nam, numb;
if(val[0] == 0)
Child* ptr = new Child(nam, val);
else
Parent* ptr = new Parent(nam, val);
myMap.insert(Maptype::value_type(numb, ptr) );
Is it legal to pass Child* ptr object as Parent* ptr object? I've heard that they have the same pointer type, so it should be alright. Then why am I getting warning: unused variable 'ptr' warning: unused variable 'ptr' error: 'ptr' was not declared in this scope ? My program works fine with Parent class only. I feel like I haven't inherited Parent right.