error using CArray(使用 CArray 时出错)
问题描述
所以,我正在尝试像这样使用 CArray
:
So, I am trying to use CArray
like this :
CArray<CPerson,CPerson&> allPersons;
int i=0;
for(int i=0;i<10;i++)
{
allPersons.SetAtGrow(i,CPerson(i));
i++;
}
但是在编译我的程序时,我得到了这个错误:
But when compiling my program, I get this error :
"错误 C2248: 'CObject::CObject' :无法访问声明的私有成员在CObject"类中 c:program文件微软视觉工作室9.0vcatlmfcincludeafxtempl.h"
"error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject' c:program filesmicrosoft visual studio 9.0vcatlmfcincludeafxtempl.h"
我什至不明白这是从哪里来的.
I don't even understand where this is coming from.
帮助!
推荐答案
你得到的错误是因为你试图使用 CArray
作为我可以收集的返回值.如果您将其从返回 CArray
更改为采用引用参数,则将编译.
The error you are getting is because you are trying to use a CArray
as a return value from what I can gather. If you change it from returning a CArray
to taking a reference parameter instead, that will compile.
试试这个:
class CPerson
{
public:
CPerson();
CPerson(int i);
void operator=(const CPerson& p) {}
private:
char* m_strName;
};
CPerson::CPerson()
{}
CPerson::CPerson(int i)
{
sprintf(m_strName,"%d",i);
}
void aFunction(CArray<CPerson,CPerson&> &allPersons)
{
for(int i=0;i<10;i++)
{
allPersons.SetAtGrow(i,CPerson(i));
i++;
}
}
这篇关于使用 CArray 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 CArray 时出错


- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- Stroustrup 的 Simple_window.h 2022-01-01
- C++ 协变模板 2021-01-01
- 从python回调到c++的选项 2022-11-16