What happens when you attempt to compile and run the following code?
#include
using namespace std;
template
void f(A &a)
{
cout<<1< } void f(int &a) { cout<<2< } int main() { int a = 1; f(a); return 0; }
Suggested Answer: B
Get Premium CPP Questions
as Interactive Web-Based Practice Test or PDF
Real Exam Format
Detailed Explanations
Instant Access
Get Your Practice Test
11 comments · newest first
LO
Louis
11 months ago
Compilation error? That sounds weird, but I guess anything's possible!
AL
Altha
11 months ago
Wait, are you sure? I thought templates would take precedence.
HE
Heike
11 months ago
Definitely outputs 2, no doubt about it!
JE
Jennie
11 months ago
I think it should show 1, right?
EL
Ellen
12 months ago
The program displays: 2
LE
Leota
12 months ago
Okay, let me walk through this. There's a template function `f(A &a)` and a non-template function `f(int &a)`. When we call `f(a)`, the non-template function should be the better match, so the output should be 2.
JA
Jannette
12 months ago
Ah, I see what's going on! The more specific `f(int &a)` function will be called, so the output should be 2. I'm confident I can solve this one.
JO
Jonelle
1 year ago
Hmm, I'm a bit confused. The code seems straightforward, but I'm not sure which function will be called. I'll have to think this through step-by-step.
AM
Amalia
1 year ago
This looks like a tricky template function question. I'll need to carefully consider the function overloading rules and how they apply here.
TH
Theron
1 year ago
Hmm, I'm a bit unsure about this one. The question mentions a "unique solution" for each question, so I'm not sure if this is the only correct answer or if there might be other ways to approach it.
MA
Maryann
1 year ago
I'm pretty confident about this one. The server is removed from the All Servers group, and scheduled backups for the server will be discontinued. Those are the two results I'm going with.