I have base class called Base and a derived class of Base called Derived, A Base Class pointer can point to a derived class object and can also access its resource but I am getting an error doing the same.
class Base
{
public:
int a;
};
class Derived : public Base
{
public:
float b;
void DoSomething()
{
cout<<"Derived";
}
};
int main()
{
Base * pBase = new Derived();
pBase->DoSomething();
pBase->a = 5;
pBase->b = 0.2f;
return 0;
}
This gives me an error
main.cpp: In function ‘int main()’:
main.cpp:34:25: error: ‘class Base’ has no member named ‘DoSomething’
pBase->DoSomething();
^
main.cpp:36:12: error: ‘class Base’ has no member named ‘b’
pBase->b = 0.2f;
^
Pardon me if its too basics, I am a beginner in c++