2 Attachment(s)
I have problem to compile my code - don't see reason why - need help - i add the code.
Hi All,
I'm using visual 2005 to write some simple C++ program using MFC.
I add the relevant file to here - the compile error that i getting is
error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject'
When i click the error then the comiler jump to the last line of the h file.
I check and i don't try to access to any private member of CObject.
I don't see any problem - and i need help.
Thanks.
Re: I have problem to compile my code - don't see reason why - need help - i add the
Please post the line where the Editor points to, when you double-click the error in the Output Window.
Hope this helps,
Usman.
1 Attachment(s)
Re: I have problem to compile my code - don't see reason why - need help - i add the code.
I add screen shot.
The line is 34 in the h file - this is the last line that contain the " }; " of the h file.
Re: I have problem to compile my code - don't see reason why - need help - i add the code.
if you perform anything which requires copy constructor and you haven't declared yours in the code, then you can get such error
Re: I have problem to compile my code - don't see reason why - need help - i add the code.
In addition to alex_gusev's reply...
This is from MSDN:
Quote:
CObject::operator =
void operator =( const CObject& src );
Remarks
The standard C++ default class assignment behavior is a member-by-member copy. The presence of this private assignment operator guarantees a compiler error message if you assign without the overridden operator. You must therefore provide an assignment operator in your derived class if you intend to assign objects of your derived class.
Example
See the example for CObList::CObList.
Re: I have problem to compile my code - don't see reason why - need help - i add the code.
T H A N K S !!!!!
I add copy constructor and now all work fine.
Re: I have problem to compile my code - don't see reason why - need help - i add the code.
Quote:
Originally Posted by alex_gusev
if you perform anything which requires copy constructor and you haven't declared yours in the code, then you can get such error
If copy constructor is needed and was not implemented, compiler would flag error:
error C2558: class 'CMyFile' : no copy constructor available
It is hard to draw any conclusion but the problem is most likely not a header file; the real problem is created somewhere in the source files where you are trying to access something.
Yu should check what cpp is compiled just before this error is flagged.
The best would be if you post entire project.
Re: I have problem to compile my code - don't see reason why - need help - i add the
Quote:
Originally Posted by JohnCz
If copy constructor is needed and was not implemented, compiler would flag error:
error C2558: class 'CMyFile' : no copy constructor available
I guess CMyFile class actually had copy constructor inherited from CObject, but could not access it
Re: I have problem to compile my code - don't see reason why - need help - i add the
You are right, providing that MyFile type was cast to CObject.