2011. 12. 9. 17:13 안드로이드/참고

1>c:\program files (x86)\microsoft visual studio 9.0\vc\atlmfc\include\afxtempl.h(267) : error C2248: 'CObject::CObject' : private 멤버('CObject' 클래스에서 선언)에 액세스할 수 없습니다.
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(561) : 'CObject::CObject' 선언을 참조하십시오.
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(532) : 'CObject' 선언을 참조하십시오.
1>        이 진단은 컴파일러 생성 함수 'CArray<TYPE,ARG_TYPE>::CArray(const CArray<TYPE,ARG_TYPE> &)'에서 수행되었습니다.
1>        with
1>        [
1>            TYPE=CSong,
1>            ARG_TYPE=CSong &
1>        ]

위와 같은 오류가 날때 확인 해야 할 사항
* 복사 생성자를 구현 해줬는가?

먼저 CObject::CObject 를 확인 해보자


/////////////////////////////////////////////////////////////////////////////
// class CObject is the root of all compliant objects

class AFX_NOVTABLE CObject
{
public:

// Object model (types, destruction, allocation)
 virtual CRuntimeClass* GetRuntimeClass() const;
 virtual ~CObject() = 0;  // virtual destructors are necessary

 // Diagnostic allocations
 void* PASCAL operator new(size_t nSize);
 void* PASCAL operator new(size_t, void* p);
 void PASCAL operator delete(void* p);
#if _MSC_VER >= 1200
 void PASCAL operator delete(void* p, void* pPlace);
#endif

#if defined(_DEBUG) && !defined(_AFX_NO_DEBUG_CRT)
 // for file name/line number tracking using DEBUG_NEW
 void* PASCAL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
#if _MSC_VER >= 1200
 void PASCAL operator delete(void *p, LPCSTR lpszFileName, int nLine);
#endif
#endif

 // Disable the copy constructor and assignment by default so you will get
 //   compiler errors instead of unexpected behaviour if you pass objects
 //   by value or assign objects.
protected:
 CObject();
private:
 CObject(const CObject& objectSrc);              // no implementation
 void operator=(const CObject& objectSrc);       // no implementation

// Attributes
public:
 BOOL IsSerializable() const;
 BOOL IsKindOf(const CRuntimeClass* pClass) const;

// Overridables
 virtual void Serialize(CArchive& ar);

#if defined(_DEBUG) || defined(_AFXDLL)
 // Diagnostic Support
 virtual void AssertValid() const;
 virtual void Dump(CDumpContext& dc) const;
#endif

// Implementation
public:
 static const CRuntimeClass classCObject;
#ifdef _AFXDLL
 static CRuntimeClass* PASCAL _GetBaseClass();
 static CRuntimeClass* PASCAL GetThisClass();
#endif
};

위와 같이 private 으로 선언되어 있다. 그럼 클래스를 어떻게 선언 했는지 보자

/////////////////////////////////////////////////////////////////////////////
// CSong
class CSong
{
 // Construction
public:
 CSong()
 {
  strSongID  = _T("");
  strTitle  = _T("");
 }

    CSong( const CSong &s )
 {
  *this = s;
 }

 const CSong& operator=(const CSong& src)
 {
  strSongID  = src.strSongID;
  strTitle  = src.strTitle;

  return *this;
 }

 // Attributes
public:
 CString    strSongID;  // Song ID
 CString    strTitle;  // Song title

 // Operations
public:
 virtual CSong* Clone()
 {
  CSong* pInfo = new CSong;
  *pInfo = *this;
  return pInfo;
 }

 virtual void Clear()
 {
  strSongID  = _T("");
  strTitle  = _T("");
 }
};

/////////////////////////////////////////////////////////////////////////////
// CSongList

class CSongList
{
 // Construction
public:
 CSongList() {}

 const CSongList& operator=(const CSongList& src)
 {
  songList.Copy(src.songList);

  return *this;
 }

 // Attributes
public:
 CArray<CSong, CSong&> songList;

 // Operations
public:
 virtual CSongList* Clone()
 {
  CSongList* pInfo = new CSongList;
  *pInfo = *this;
  return pInfo;
 }

 virtual void Clear()
 {
  songList.RemoveAll();
 }
};

CSongList 에 복사 생성자가 없다.
구현 해보자

/////////////////////////////////////////////////////////////////////////////
// CSongList

class CSongList
{
 // Construction
public:
 CSongList() {}

    CSongList( const CSongList &s )
 {
  *this = s;
 }

 const CSongList& operator=(const CSongList& src)
 {
  songList.Copy(src.songList);

  return *this;
 }

 // Attributes
public:
 CArray<CSong, CSong&> songList;

 // Operations
public:
 virtual CSongList* Clone()
 {
  CSongList* pInfo = new CSongList;
  *pInfo = *this;
  return pInfo;
 }

 virtual void Clear()
 {
  songList.RemoveAll();
 }
};

오류가 해결 되었다.

posted by townone