Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CArray

Status
Not open for further replies.

Warrioruw

Programmer
Jan 30, 2004
24
0
0
CA
Hi all,

I have a CArray of struct, and I want to assign or add a new element of struct type to the CArray, but got error message, something like "No = operator" or "No constructor for struct".

Here is the sample code:

struct Sample{
CUIntArray Index;
CRect Rct;
CDblPoint Point; //user defined data type
};

Sample abc;
CArray<Sample, Sample> def;
def.Add(abc); // or def[0]=abc;


Thanks.
 
>"No = operator"

Ie your struct should have an assignment operator

>"No constructor for struct".

Your struct should also have a copy constructor.


/Per
[sub]
&quot;It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure.&quot;[/sub]
 
Is it possible to add copy constructor or assignment operator to struct? As far as I know, it can be done in class. If it is possible, could you tell me how to do that?

Thanks
 
Another question is that when I try to use member function of CArray<Sample, Sample> def, the list of functions didn't not show up. I had #include <afxtempl.h>.


Thanks
 
Example of struct with constructor
Code:
struct MyStruct
{
	double d;
	char c;
	MyStruct(){};

	MyStruct( MyStruct & r)
	{
		d=r.d;
		c=r.c;
	}

	MyStruct & operator=(MyStruct & r)
	{
		this->d=r.d;
		this->c =r.c;
		return *this;
	}

};
As I can see, I suggest you to implement SAMPLE as a class derived from CObject and if you want to use array then use CPtrArray to store pointers to the SAMPLE objects.
-obislavu-
 
If you try to use the CArray::IsEmpty method, you cannot do it if you use VC6, this method is available only from VC7
there are additional methods documented in msdn that are available from VC7 and later
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top