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 6 Question 82 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 82
Topic #: 6
[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:

Lashaunda
6 months ago
I'm not sure, but I think there might be a compilation error
upvoted 0 times
...
Nana
7 months ago
I'm with User 1, I think the program will display: Hello world!
upvoted 0 times
...
Herminia
7 months ago
I disagree, I believe there will be a compilation error
upvoted 0 times
...
Meaghan
7 months ago
I think the program will display: Hello world!
upvoted 0 times
...
Lazaro
8 months ago
Because the add function for string is not defined in the class template.
upvoted 0 times
...
Tamera
8 months ago
Why does that happen?
upvoted 0 times
...
Lazaro
8 months ago
Template specialization error
upvoted 0 times
...
Tamera
8 months ago
What error will be displayed?
upvoted 0 times
...
Lazaro
8 months ago
B) compilation error
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