Deal of The Day! 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 - C++ Certified Professional Programmer exam
Question #: 82
Topic #: 6
[All CPP - C++ Certified Professional Programmer 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:

Lazaro
3 days ago
Because the add function for string is not defined in the class template.
upvoted 0 times
...
Tamera
4 days ago
Why does that happen?
upvoted 0 times
...
Lazaro
5 days ago
Template specialization error
upvoted 0 times
...
Tamera
6 days ago
What error will be displayed?
upvoted 0 times
...
Lazaro
7 days ago
B) compilation error
upvoted 0 times
...

Save Cancel