C++ Institute C++ Certified Professional Programmer CPP Question # 67 Topic 7 Discussion

C++ Institute C++ Certified Professional Programmer CPP Question # 67 Topic 7 Discussion

CPP Exam Topic 7 Question 67 Discussion:
Question #: 67
Topic #: 7

What happens when you attempt to compile and run the following code?

#include

#include

class A {

public:

virtual int f() { return 10; }

virtual ~A(){}

};

class B: public A {

int f() {return 11; }

virtual ~B(){}

};

int main (){

std::vectorv1;

for(int i = 10; i>0; i??)

{

i%2>0?v1.push_back(new A()):v1.push_back(new B());

}

std::vector::iterator it = v1.begin();

while(it != v1.end())

{

std::cout<f()<<" ";

v1.pop_back();++it;

}

return 0;

}


A.

destructor of class A will be called


B.

destructor of class B will be called


C.

code will not compile


D.

program outputs 10 11 10 11 10


E.

program outputs 10 11 10 11 10 11 10 11 10 11


Get Premium CPP Questions

Contribute your Thoughts:


Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.