调试版本中的CObject复制构造函数错误(C2248) [英] CObject Copy constructor Error(C2248) in debug build

查看:110
本文介绍了调试版本中的CObject复制构造函数错误(C2248)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我一直在尝试调试一个应用程序,但它只在调试中给出了错误

build。发布版本工作正常。我需要更改一些项目设置或排除一些dll吗?

i在输出窗口中获取以下调试输出消息。



C:\\ \\ Program Files \ Microsoft Visual Studio 10.0 \VC \atlmfc\include\afxtempl.h(262):错误

C2248:''CObject :: CObject'':无法访问私有在类''CObject'中声明的成员'



C:\Program Files \ Microsoft Visual Studio 10.0\VC\atlmfc\include\afx。 h(535):参见

声明''CObject :: CObject''



C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\afx.h(510):请参阅

声明''CObject''



此诊断发生在编译器生成的函数中

''CArray< type,arg_type> :: CArray(const CArray< type,arg_type>&)''

with

[

TYP E = CString,

ARG_TYPE = CString

]

Hi to all. I have been trying to debug an application but it is giving me error only in debug
build. release build works fine. do i need to change some project settings or exclude some dlls?
i get the following debug output message in output window.

C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\afxtempl.h(262): error
C2248: ''CObject::CObject'' : cannot access private member declared in class ''CObject''

C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\afx.h(535) : see
declaration of ''CObject::CObject''

C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\afx.h(510) : see
declaration of ''CObject''

This diagnostic occurred in the compiler generated function
''CArray<type,arg_type>::CArray(const CArray<type,arg_type> &)''
with
[
TYPE=CString,
ARG_TYPE=CString
]

推荐答案

这是一个保护:):

This is a protection :) :
private:
    CObject(const CObject& objectSrc);              // no implementation



...而 CArray 类没有复制构造函数。



为什么它是保护?

CArray 不知道必须如何复制其成员,以及 CObject (base)。 .. :)



所以,例如,代码:


...while the CArray class has not a copy constructor.

Why is it a "protection" ?
CArray do not know how its members must be copied, and CObject (base) as well... :)

So, for example, the code:

{
  CArray<CString>* pArray(new CArray<CString>);
  pArray->Add(_T("One"));
  pArray->Add(_T("Two"));

  CArray<CString> arTest(*pArray);

  delete pArray;
  pArray = NULL;

  TCHAR tchTest(arTest[0].GetAt(1) + arTest[1].GetAt(2));
}



...可能会在最后一行发生崩溃:)


... may provide a crash at its last line :)


这篇关于调试版本中的CObject复制构造函数错误(C2248)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆