Vectors.

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
class A
{
private:
int AA;
int qq;
string bb;
public:
virtual void display()
}

class B : class A
{
private:
int BB;
public:
void display()
}

class C : class A
{
private:
int CC;
public:
void display()
}


when i run the c.display() it will invoke display() from C, am i right to say that?

what if:

1
2
3
4
5
6
7
8
9
10
11
int main()
{
vector <A *> AA(4);
AA[0] = new BB(1,2,3);
AA[1] = new BB(2,3,4);
AA[2] = new CC(3,4,5);
AA[3] = new CC(6,7,8);

for (int i =0; i <4; i++)
AA[i] ->display(); // this.display will call which class display?
}
Why don't you make each display() method print something different, then run your main() above and see what prints? That will tell you which one is being called.
The main function shouldn't compile. What is the BB type? What is the CC type? They are variable names not types.
I agree the easy thing would be to have each print something diferent
Last edited on
Topic archived. No new replies allowed.