What happens if the following C++ program is compiled?
#include <iostream>
#include <string>
using namespace std;
class A
{
int a;
public:
A(){
a = 0;
}
void show(){
a++;
cout<<"a: "<<a<<endl;
}
};
class B: private A
{
public:
void show(){
show();
}
};
int main(int argc, char const *argv[])
{
B b;
b.show();
return 0;
}
#include <iostream>
#include <string>
using namespace std;
class A
{
int a;
public:
A(){
a = 0;
}
void show(){
a++;
cout<<"a: "<<a<<endl;
}
};
class B: private A
{
public:
void show(){
show();
}
};
int main(int argc, char const *argv[])
{
B b;
b.show();
return 0;
}
A. Error because of the conflicts between two show() function in class B
B. Program will compile successfully
C. Error due to self call in show() function
D. Error because show() function from class A is derived privately
Answer: Option B
Join The Discussion