BlackFriday 2024! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute Exam CPP Topic 8 Question 80 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 80
Topic #: 8
[All CPP Questions]

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

#include

#include

using namespace std;

template

class A {

T_v;

public:

A() {}

A(T v): _v(v){}

T getV() { return _v; }

void add(T & a);

void add(string & a);

};

template

void A::add(T & a) { _v+=a; }

void A::add(string & a) {

_v.insert(0, a);

}

int main()

{

Aa("Hello");

string s(" world!");

a.add(s);

cout << a.getV() <

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

Rolf
4 months ago
I don't think there will be a compilation error since the syntax seems correct
upvoted 0 times
...
Nickie
5 months ago
But what if there's a compilation error? That's also a possibility, right?
upvoted 0 times
...
Alexis
5 months ago
I agree, because the code looks like it will insert 'world!' in front of 'Hello'
upvoted 0 times
...
Rosann
5 months ago
I think the program will display: Hello world!
upvoted 0 times
...
Annmarie
5 months ago
I think the program will display: world!Hello
upvoted 0 times
...
Hannah
5 months ago
I think the correct answer is: Hello world!
upvoted 0 times
...
Edna
6 months ago
I'm not sure, but I think it will display: Hello world!
upvoted 0 times
...
Rashida
6 months ago
I believe it will result in a compilation error
upvoted 0 times
...
Sharan
6 months ago
I think it will display: Hello world!
upvoted 0 times
...

Save Cancel