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

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77