Output of Code

Does anyone know what the output of this code is?

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
  #include <iostream>
using namespace std;

class Cat {
public:
virtual void speak()
{
cout << "meow" << endl;
}
};

class Lion : public Cat {
public:
void speak()
{
cout << "roar" << endl;
}
};

int main()
{
Lion l;
Cat c = l;
Cat* cPtr = &l;
Cat& cRef = l;

l.speak();
c.speak();
cPtr->speak();
cRef.speak();

return 0;
}
This is a good bookmark to have: http://codepad.org/
You could always run the program and see what the output is?
but it looks like both the animals "speak" twice
Last edited on
@ giblit: Line 24 is a trick called Polymorphism: http://www.cplusplus.com/doc/tutorial/polymorphism/
giblit I can not run the program that is the problem.

computergeek01 what should i do in order to run this program? I deleted that so called trick, but it did not help just gave me an extra error to deal with.
I never said to delete anything. This code is fine, copy and paste the error you are getting into your next post.
I just had to add system("pause") and I was able to see the output beginner mistake Thank you though
I posted another question if you could tell me if i did that right
Modify the following code to:
Declare class A to be a friend of class B.
Declare function double compute(A& data) to be a friend of class A.

1
2
3
4
5
6
7
8
9
class A
{
friend double compute (A& data)
};

class B
{
friend class A;
}; 


Topic archived. No new replies allowed.