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 CPP Exam - Topic 8 Question 125 Discussion

Posted by Candida on Jun 21, 2026 at 03:59 PM

What will happen when you attempt to compile and run the following code? Choose all possible answers.

#include

using namespace std;

class B {};

template

class A {

T_v;

public:

A() {}

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

T getV() { return _v; }

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

};

int main()

{

A a(1);

Ab;

a.add(10);

cout << a.getV() <

return 0;

}

Suggested Answer: A, C

Get Premium CPP Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
14 comments · newest first
SH
Sherron 1 month ago
I feel like it will display 11. The logic seems correct.
GO
Golda 2 months ago
No way, it should compile. The add function works fine.
NO
Norah 2 months ago
I believe it will compile but throw an exception.
FE
Felicidad 2 months ago
Yeah, I agree. The template has a typo with _v.
DO
Dorsey 2 months ago
I think the program will not compile.
AD
Adela 2 months ago
I’m surprised this code even runs at all!
MI
Michal 2 months ago
It should display 11 after adding 10.
FA
Fanny 3 months ago
Wait, what's up with T_v? Is that a typo?
IR
Irving 3 months ago
I think it will compile just fine.
BE
Becky 3 months ago
Program will not compile.
RO
Roxanne 3 months ago
I feel like the program should run fine and display 11, but I can't shake the feeling that there's something wrong with the class B definition.
VI
Vincenza 3 months ago
I practiced a similar question where a template had an issue with a missing member variable. I wonder if that's what's happening here too.
MA
Malcolm 3 months ago
I remember something about templates needing to be defined correctly, so I'm leaning towards option B, that it won't compile.
FE
Fernanda 4 months ago
I think the program will compile, but I'm not entirely sure about the template syntax.
0/2000 characters