错误使用CArray [英] error using 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:\程序
files\microsoft visual studio
9.0 \vc\atlmfc\include\afxtempl.h
"error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject' c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtempl.h"
我甚至不明白这是从哪里来的。
I don't even understand where this is coming from.
HELP!
推荐答案
你得到的错误是因为你试图使用 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)
{
int i=0;
for(int i=0;i<10;i++)
{
allPersons.SetAtGrow(i,CPerson(i));
i++;
}
}
这篇关于错误使用CArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!