class thread_str
{
public:
DWORD ThreadID;
CArray<char * ,char *> ptParams;
CArray<char * ,char *> ptCols;
int flag;
}CArray<thread_str,thread_str> ptThread;
void InitThread()
{
thread_str thread;
ThreadID=1234;
for(int i=0;i<100;i++)
{
thread.ptParams.SetSize(thread.ptParams.GetSize()+1,-1);
thread.ptCols.SetSize(thread.ptCols.GetSize()+1,-1);
strcpy(thread.ptParams[i],"kjfdsjsdjflskdjflkds");
strcpy(thread.ptCols[i],"lkjfdkasjflksdjf");
ptThread.Add(thread); }
}麻烦各位帮我看下,如果不行的话,有什么好的解决方法吗?我现在就要想把一个类的对象写如数组,
对于类中的数组的动态的添加。谢谢
{
public:
DWORD ThreadID;
CArray<char * ,char *> ptParams;
CArray<char * ,char *> ptCols;
int flag;
}CArray<thread_str,thread_str> ptThread;
void InitThread()
{
thread_str thread;
ThreadID=1234;
for(int i=0;i<100;i++)
{
thread.ptParams.SetSize(thread.ptParams.GetSize()+1,-1);
thread.ptCols.SetSize(thread.ptCols.GetSize()+1,-1);
strcpy(thread.ptParams[i],"kjfdsjsdjflskdjflkds");
strcpy(thread.ptCols[i],"lkjfdkasjflksdjf");
ptThread.Add(thread); }
}麻烦各位帮我看下,如果不行的话,有什么好的解决方法吗?我现在就要想把一个类的对象写如数组,
对于类中的数组的动态的添加。谢谢
解决方案 »
- 如何设置共享文件夹的权限?
- 谁有EXCEL OLE对象操作的帮助文档啊?
- 菜单类类名是#32768,别的类名去哪儿找?
- 关于网卡配置的问题:我一个机子上装了两块网卡 通过一个网卡发包 另一个网卡收包 要求数据包中间要经过一个三层交换机(55分)
- 一直模模糊糊的UNICODE概念:宽窄字串转换和编码转换的区别?
- 如何释放CObArray对象中的元素指针指向的内存?
- 请问什么是"内核",作用是什么
- 这条SQL语句如何写
- 什么命令能让项目整个退出?(给F)
- 请问使用CDC类,使画出的东西总在View的最前面,不被其它东西覆盖掉?
- 急求啊,急,急,急!!如何在vc++中实现word程序中的标注功能并在打印中显示标注呢?
- 问几个关于CToolBar的问题和CImageList的问题
错误信息为:
error C2664: 'Add' : cannot convert parameter 1 from 'class thread_str' to 'class thread_str'
No copy constructor available for class 'thread_str'
那么我的对象里的数组动态增加或减少,会有影响吗?
--------------------------------------------------------------------------------
The information in this article applies to:Microsoft Visual C++, 32-bit Editions, versions 5.0, 6.0--------------------------------------------------------------------------------
SYMPTOMS
When a user-defined class contains a CArray and the same user-defined class is nested in another class, you may get the following errors if no copy constructor and assignment operator are provided for the class: main.cpp(52): error C2664: 'Add' : cannot convert parameter 1 from 'class B' to 'class B' No copy constructor available for class 'B'
After adding a copy constructor, you get the following error message:
afxtempl.h(443): error C2582:'B' : 'operator =' function is unavailable afxtempl.h(1566):while compiling class-template member function 'void __thiscall CArray<class B,class B>::SetAtGrow(int,class B)' CAUSE
If the class that contains a CArray is nested in another class, then its objects must be copied.The compiler does not construct an implicit copy constructor and copy assignment operator because the class in question has CArray as a member, which does not have a copy constructor and copy assignment operator, and CArray inherits from CObject, which has a protected copy construtor and a copy assignment operator. The compiler tries to generate the implicit ones, but that generates a call to CObject's version of them. Because they are protected, the above errors are generated. RESOLUTION
You need to provide a copy constructor and an assignment operator for the class. STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.MORE INFORMATION
The following example shows the correct use of the CArray class:
// No compiler option needed.
#include <afxtempl.h>struct A
{
int i;
int j;
};class B
{ public:
B();
~B(); // Need to define copy ctor and assignment operator. B(const B& b){
// Your copy ctor body goes here.
}
/* const B& */ void operator= (const B& b) {
// Your assignment operator body goes here.
} protected:
CArray<A, A> arrayA;
};B::B(){}
B::~B(){}class C
{ public:
C();
~C();
void addElement(); protected:
CArray<B, B> arrayB;
};C::C(){}
C::~C(){}
void C::addElement()
{
B temp;
arrayB.Add(temp);
}void main()
{
}