need u r help

there is an error here but i tryed my best to solve it.
can u please help me with it ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

#include<iostream>
#include<string>
using namespace std;

class Mammal
{
 public:
 Mammal():itsAge(1) { cout << "Mammal constructor...\n"; }
 ~Mammal() { cout << "Mammal destructor...\n"; }   
void Move() const { cout << "Mammal move one step\n"; }
 virtual void Speak() const { cout << "Mammal speak!\n"; }
 virtual void WagTail();
 protected:
 int itsAge;
 };

 class Dog : public Mammal{
 public:
 Dog() { cout << "Dog Constructor...\n"; }
 ~Dog() { cout << "Dog destructor...\n"; } 

virtual void WagTail() { cout << "Wagging Tail...\n"; }
 virtual void Speak()const { cout << "Woof!\n"; }   

 void Move()const { cout << "Dog moves 5 steps...\n"; }   
 };

 int main()
 {
 Mammal *pDog = new Dog;
 pDog->WagTail();                          
                  
 pDog->Speak();                   

system("pause");
return 0;
}


i did pDog->move();
becuse it doesnot run with me
By the power invested in me, I shall bring forth the error with my High School degree. Hmm didint work...

Could you please post the error?
Last edited on
yes, i try my best but when i put it in c++ program doesnot work at all
the erorr should be in 32 line pDog->WagTail();
but i dont know how to do it ,i just did pDog->move(); but i dont know
thank you so much
You need to atleast define your WagTail function in Mammal, even if its just empty. Change it to look like this -

virtual void WagTail(){}

Also, you dont need to write virtual in the functions in the Dog class.
thank you so so much bro
Topic archived. No new replies allowed.