Hi, this is the problem i am having with my assignment(the code that i am going to show here is not my assignment,i just wrote this code because i am experiancing simmular problem in my assignment)
//person.h
#include <string>
#include <iostream>
using namespace std;
class Person
{
private:
string name;
public:
Person(string nam){name=nam;}
void setName(string nam){name=nam;}
string getName(){return name;}
};
class Account:public Person
{
private:
int money;
public:
Account(int mon,string nam):Person(nam)
{money=mon;}
int getMoney(){return money;}
};
//test.cpp
#include "training.h"
int main()
{
Person *p;
p=new Account(500,"Hovo");
p->getMoney();
//Here p does not have access to getMoney function,i knowi can call static cast //and it works but i need to live the main just like this.
return 0;
}
so my question is what I am missing, why person instace which was declared to point to account does not have access to account functions, how to fix it ?