C++ | Constructors | Question 17

filter_none

edit
close

play_arrow

link
brightness_4
code

#include<iostream>
using namespace std;
  
class Test
{
public:
   Test(Test &t) { }
   Test()        { }
};
  
Test fun()
{
    cout << "fun() Called\n";
    Test t;
    return t;
}
  
int main()
{
    Test t1;
    Test t2 = fun();
    return 0;
}

chevron_right


(A) fun() Called
(B) Empty Output
(C) Compiler Error: Because copy constructor argument is non-const


Answer: (C)

Explanation: See following for details:

Why copy constructor argument should be const in C++?

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Recommended Posts:

    Article Tags :
    Practice Tags :


    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.