C++ Institute C++ Certified Professional Programmer CPP Question # 42 Topic 5 Discussion

C++ Institute C++ Certified Professional Programmer CPP Question # 42 Topic 5 Discussion

CPP Exam Topic 5 Question 42 Discussion:
Question #: 42
Topic #: 5

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;

}


A.

program will display: Hello world!


B.

compilation error


C.

program will display: world!Hello


D.

program will run without any output


Get Premium CPP Questions

Contribute your Thoughts:


Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.