source file name: privateconst.cpp
// CPP program to demonstrate usage of private constructor
#include <iostream.h>
//using namespace std;
// class A
class A{
private:
A(){
cout << "constructor of A\n";
}
friend class B;
};
// class B, friend of class A
class B{
public:
B(){
A a1;
cout << "constructor of B\n";
}
};
// Driver program
int main(){
B b1;
return 0;
}
output:
0 Comments
Post a Comment