• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech

C++ | Function Overloading and Default Arguments | Question 4

Predict the output of following C++ program? C
include<iostream>
using namespace std;
 
class Test
{
protected:
    int x;
public:
    Test (int i):x(i) { }
    void fun() const  { cout << "fun() const " << endl; }
    void fun()        {  cout << "fun() " << endl;     }
};
 
int main()
{
    Test t1 (10);
    const Test t2 (20);
    t1.fun();
    t2.fun();
    return 0;
}
Compiler Error

fun()
fun() const

fun() const
fun() const

fun()
fun()

Get 90% Course fee refund on completing 90% course in 90 days! Take the Three 90 Challenge today.

The next 90 Days of focus & determination can unlock your full potential. The Three 90 challenge has started and this is your chance to upskill and get 90% refund. What more motivation do you need? Start the challenge right away!

Last Updated :
Share your thoughts in the comments
  翻译: