Reg Copy Constructor
Hi All,
There is small doubt about the below program
class A
{
public:
A()
{
cout <<"C'tor!"<<endl;
}
A(const A& src)
{
cout <<"Copy C'to!"<<endl;
}
void display()
{
cout << "Worked!"<<endl;
}
};
int main()
{
A a = A();
ifstream obj = ifstream("notepad.txt");
return 0;
}
when we create a object like A a = A(); , according to me, this should create temporary object and then copy C'tor Should be called but this has not happened but if i make the copy C'tor of class A as private (even though it is not called or used), g++ error throws for statement A a = A();
If i create a ifstream object like above then g++ compiler throws an error like below :
"synthesized method âstd::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char, std::char_traits<char> >&)â first required here"
My concern here is if we create a object like A a = A(); why the copy C'tor should be accessible if even it is not called and consequently why for ifstream it is required if Copy C'tor is not called for user defined class (Trying to make it generic)
|