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<
v1.pop_back();++it;
}
return 0;
}
Suggested Answer: D
Get Premium CPP Questions
as Interactive Web-Based Practice Test or PDF
Real Exam Format
Detailed Explanations
Instant Access
Get Your Practice Test
6 comments · newest first
ST
Stephanie
11 months ago
Nah, I think it won't compile due to the loop condition.
AL
Alyce
12 months ago
The destructors will be called correctly.
LA
Lavonna
12 months ago
Wait, are you sure about that?
CH
Chau
1 year ago
I think it outputs 10 11 10 11 10.
MA
Maia
1 year ago
The code will compile fine.
AH
Ahmad
1 year ago
I'm pretty sure this is asking about a vSphere feature that helps with optimization challenges. I think the answer is vSphere DRS, which automatically balances workloads across hosts.