CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2004
    Posts
    21

    Question 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.
    Attached Files Attached Files
    Last edited by YANSHOF; January 19th, 2007 at 09:18 AM.

  2. #2
    Join Date
    Aug 2001
    Location
    Germany
    Posts
    1,384

    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.

  3. #3
    Join Date
    Dec 2004
    Posts
    21

    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.
    Attached Images Attached Images

  4. #4
    Join Date
    Jan 2003
    Location
    Cambridge, UK
    Posts
    752

    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
    Cheers,

    Alex
    Please rate this post if you find it helpful

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    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:
    CObject:perator =
    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.

  6. #6
    Join Date
    Dec 2004
    Posts
    21

    Thumbs up 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.

  7. #7
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    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.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  8. #8
    Join Date
    Jan 2003
    Location
    Cambridge, UK
    Posts
    752

    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
    Cheers,

    Alex
    Please rate this post if you find it helpful

  9. #9
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    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.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured