Dave's Brain

Browse - Programming Tips - What is causing this error when I compile my program:

Date: 2014jul18
Language: C++
Platform: Windows
Product: Visual C++

Q.  What is causing this error when I compile my program:

c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(1820) : error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject' 1> c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afx.h(558) : see declaration of 'CObject::CObject' 1> c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afx.h(529) : see declaration of 'CObject' 1> This diagnostic occurred in the compiler generated function 'CCmdTarget::CCmdTarget(const CCmdTarget &)'
A. You are trying to access the copy constructor of something that doesn't want to you. Its probably a MFC class or a class you made that extends a MFC class. Here is some code that caused it for me:
class MyCustomClass : CWnd { }; class MyOtherClass { MyCustomClass m_custom; public: // Attempting to return a reference to a class based on CWnd doesn't work MyCustomClass &GetCustomClassReference() { return m_custom; } // This way works MyCustomClass *GetCustomClassPointer(); { return &m_custom; } }; SomeFunction() { MyOtherClass something; MyCustomClass custom = something.GetCustomClassReference(); }

Add a comment

Sign in to add a comment
Copyright © 2008-2018, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.