简体   繁体   English

'CObject :: CObject':无法访问在'CObject'd:\\ Program Files \\ Microsoft Visual Studio 9.0 \\ vc \\ atlmfc \\ include \\ afxcoll.h中声明的私有成员

[英]'CObject::CObject' : cannot access private member declared in class 'CObject'd:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxcoll.h

This error happens while trying to send the instance of CTypedPointerList in the function parameter from one class to another class. 尝试将函数参数中的CTypedPointerList实例从一个类发送到另一类时,会发生此错误。

How to solve this issue? 如何解决这个问题?

Here is my code 这是我的代码

ObjectList.h 对象列表

#pragma once
#include "LogData.h"
typedef  CTypedPtrArray<CPtrList , CLog *> CLogData;
class CObjectList
{
    public:

CLogData m_logData;
    public:
CObjectList();
CLogData GetLog();
};

ObjectList.cpp ObjectList.cpp

#include "stdafx.h"
#include "LogData.h"

CObjectList::CObjectList()
{
}

CLogData CObjectList::GetLog()
{
return m_logData;
}

Regards, 问候,

karthik 卡尔提克

I'd need to see your code to be sure, but it looks like you're trying to pass the CTypedPointerList by value. 我需要确定您的代码,但是看来您正在尝试按值传递CTypedPointerList。 This means a copy of the instance needs to be created, thus the implicit call to the copy constructor. 这意味着需要创建实例的副本,因此对副本构造函数的隐式调用。 The authors of CTypedPointerList have marked the copy constructor private in order to indicate that copies of this class cannot be made. CTypedPointerList的作者已将复制构造函数标记为私有,以指示无法创建此类的副本。

Try passing by reference (perhaps a const reference?). 尝试按引用传递(也许是const引用?)。 If you truly do need a copy, you may need to do this manually. 如果确实需要副本,则可能需要手动进行。

EDIT 编辑

Ahh... you're using the instance as a return value. 啊...您正在使用实例作为返回值。 The GetLog() method returns a copy of the instance, and since the instance cannot be copied, it does not compile. GetLog()方法返回该实例的副本 ,并且由于无法复制该实例,因此无法编译该实例。 I expect what you really want to do is return a const reference to the instance. 我希望您真正想要做的是返回对该实例的const引用。 This means client will get a read-only reference to the log, no copy is made. 这意味着客户端将获得对该日志的只读引用,而不进行任何复制。 To achieve this, change the return type of GetLog() to const CLogData & in both the h and cpp files. 为此,在h和cpp文件GetLog()的返回类型更改为const CLogData &

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 &#39;CObject :: CObject&#39;:无法访问在类&#39;CObject&#39;中声明的私有成员 - 'CObject::CObject' : cannot access private member declared in class 'CObject' 错误C2248:'CObject :: CObject':无法访问类'CObject'afxwin.h中声明的私有成员 - error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject' afxwin.h VS2013编译器:“ CObject :: CObject”:无法访问在类“ CObject”中声明的私有成员 - VS2013 compiler: 'CObject::CObject' : cannot access private member declared in class 'CObject' 无法访问在类“ CObject”中声明的私有成员 - Cannot access private member declared in class 'CObject' 无法访问在类“ CObject”中声明的私有成员? - Cannot access private member declared in class 'CObject'? CPtrList 无法使用:错误 C2248:“CObject::operator =”:无法访问类“CObject”中声明的私有成员 - CPtrList cannot use: error C2248: 'CObject::operator =' : cannot access private member declared in class 'CObject' 使用CArray时出错:无法访问在类CObject中声明的私有成员 - Error using CArray: cannot access private member declared in class CObject 错误 C2248: 'CObject::CObject': 当我在 ZD7421054471AB272ZCEAC18FD97BBD237 - error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject' when I calling hDC.SelectObject function in MFC 试图传递CStringArray给出错误无法访问类'CObject'中声明的私有成员 - Trying to pass a CStringArray gives error cannot access private member declared in class 'CObject' 向CArray添加数据会产生错误“无法访问在类&#39;CObject&#39;中声明的私有成员” - Adding data to CArray gives error “cannot access private member declared in class 'CObject'”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM