Strange linked list behaviour

G

Guest

h
I use the following statements in my code
typedef struct _MYSTRUCT
[...
CDWordArray myarray
}MYSTRUCT

CList<MYSTRUCT> mystruct

This code won't compile with some strange failure in afxtempl.h (seems as if CDWordArray were a linked list too)

Can anyone help me out of this

Thanks a lot
Gordon
 
B

Bo Persson

Gordon Knote said:
hi
I use the following statements in my code:
typedef struct _MYSTRUCT{
[...]
CDWordArray myarray;
}MYSTRUCT;

CList<MYSTRUCT> mystruct;

This code won't compile with some strange failure in afxtempl.h (seems as
if CDWordArray were a linked list too).

It might be easier if you told us WHAT strange failure you get.
 
C

Carl Daniel [VC++ MVP]

Gordon said:
hi
I use the following statements in my code:
typedef struct _MYSTRUCT{
[...]
CDWordArray myarray;
}MYSTRUCT;

CList<MYSTRUCT> mystruct;

This code won't compile with some strange failure in afxtempl.h
(seems as if CDWordArray were a linked list too).

Can anyone help me out of this?

You could get rid of the C-ism and just try

string MYSTRUCT
{
CDWordArray myarray;
};

Clist<MYSTRUCT> mystruct;

The typedef idiom is not needed in C++ since the struct-tag name defines a
type in C++ (but not in C).

-cd
 
G

Guest

The complete failure message (from the compiler) is

error C2582: The function 'operator =' is not available in '_MYSTRUCT

The error occurs in afxtempl.h, line 1210
 
C

Carl Daniel [VC++ MVP]

Gordon said:
Just causes the same error. Any ideas why?

Based on the error message that you posted elsewhere, it sounds like your
struct doesn't have an assignment operator. Normally the compiler will
write an assignment operator for you, but if you have a data member of the
struct with an inaccessible assignment operator, the compiler won't be able
to generate the assignment operator for you.

Apparently CDWordArray declares a private assignment operator, since the
following pasted into a simple MFC application produces the same errors:

#include <afxtempl.h>
struct S
{
CDWordArray arr;
};

CList<S> list;

Personally I'd dump all the MFC collection classes and use standard library
classes instead. Replace CDWordArray with std::vector and Clist with
std::list.

#include <vector>
#include <list>

struct S
{
std::vector<DWORD> arr;
};

std::list<S> slist;

Of course, the interface of std::vector is not the same as CDWordArray, nor
is std::list the same as CList<T>, so you'll have to make changes elsewhere
as well.

-cd
 
B

Bronek Kozicki

The complete failure message (from the compiler) is:

error C2582: The function 'operator =' is not available in '_MYSTRUCT'

check if you have const member or reference inside your structure. These
members may not be assigned to, thus preventing compiler from generating
own assigment operator for your struct.


B.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top