How to create and array of structs that have their own arrays? [modified]
-
Hello :) , is there anyway that I can hold an array of structs that have their own arrays other than creating a new class
somewhere in the typedef.h ...
typedef struct mystruct
{
CStringArray aName1;
CStringArray aName2;
CArray aVal1;
CArray aVal2;
}MY_STRUCT;somewhere in the header of my MyDoc.h...
#include "typedef.h"CArray m_MyStructs;
somewhere in the header of my MyDoc.cpp...MY_STRUCT a;
...
m_MyStruct.Add(a);This code returns error that "=" operator is private and can't be accessed! Thanks :) PS-Oh I got that I can'tuse >< around my type specifier because it will be assumed as a tag so I use [] instead :) somewhere in the typedef.h ... typedef struct mystruct { CStringArray aName1; CStringArray aName2; CArray [int] aVal1; CArray [int] aVal2; }MY_STRUCT;
-
Hello :) , is there anyway that I can hold an array of structs that have their own arrays other than creating a new class
somewhere in the typedef.h ...
typedef struct mystruct
{
CStringArray aName1;
CStringArray aName2;
CArray aVal1;
CArray aVal2;
}MY_STRUCT;somewhere in the header of my MyDoc.h...
#include "typedef.h"CArray m_MyStructs;
somewhere in the header of my MyDoc.cpp...MY_STRUCT a;
...
m_MyStruct.Add(a);This code returns error that "=" operator is private and can't be accessed! Thanks :) PS-Oh I got that I can'tuse >< around my type specifier because it will be assumed as a tag so I use [] instead :) somewhere in the typedef.h ... typedef struct mystruct { CStringArray aName1; CStringArray aName2; CArray [int] aVal1; CArray [int] aVal2; }MY_STRUCT;
Could you report the exact (complete) error message?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Could you report the exact (complete) error message?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]Hi :) , Sure, Error 36 error C2248: 'CObject::operator =' : cannot access private member declared in class 'CObject' c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxcoll.h 593 Error 37 error C2248: 'CObject::operator =' : cannot access private member declared in class 'CObject' c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxtempl.h 272 these errors do not appear when I remove
m_Mystruct.Add(a)
As I noted in the stuct definition I have both CArray and CStringArray thanks :) -
Hi :) , Sure, Error 36 error C2248: 'CObject::operator =' : cannot access private member declared in class 'CObject' c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxcoll.h 593 Error 37 error C2248: 'CObject::operator =' : cannot access private member declared in class 'CObject' c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxtempl.h 272 these errors do not appear when I remove
m_Mystruct.Add(a)
As I noted in the stuct definition I have both CArray and CStringArray thanks :)Could you also reformat your code properly? For instance CArray is a template container, but I don't see any argument between
< >
. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hello :) , is there anyway that I can hold an array of structs that have their own arrays other than creating a new class
somewhere in the typedef.h ...
typedef struct mystruct
{
CStringArray aName1;
CStringArray aName2;
CArray aVal1;
CArray aVal2;
}MY_STRUCT;somewhere in the header of my MyDoc.h...
#include "typedef.h"CArray m_MyStructs;
somewhere in the header of my MyDoc.cpp...MY_STRUCT a;
...
m_MyStruct.Add(a);This code returns error that "=" operator is private and can't be accessed! Thanks :) PS-Oh I got that I can'tuse >< around my type specifier because it will be assumed as a tag so I use [] instead :) somewhere in the typedef.h ... typedef struct mystruct { CStringArray aName1; CStringArray aName2; CArray [int] aVal1; CArray [int] aVal2; }MY_STRUCT;
I guess it is because CArray and CStringArray don't have a copy constructor. So, the compiler will assign a default copy constructor and assignment operator to your structure which 'uses' the copy ctor and assignment operator of the CArray and CStringArray, which are private. One way to fix this is to provide your own copy constructor and assignment operators for the structure. In those, copy the contents of the arrays using a loop (instead of a direct assignment).
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
Could you also reformat your code properly? For instance CArray is a template container, but I don't see any argument between
< >
. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]done :)
-
I guess it is because CArray and CStringArray don't have a copy constructor. So, the compiler will assign a default copy constructor and assignment operator to your structure which 'uses' the copy ctor and assignment operator of the CArray and CStringArray, which are private. One way to fix this is to provide your own copy constructor and assignment operators for the structure. In those, copy the contents of the arrays using a loop (instead of a direct assignment).
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++Hi! :) I guess you are right! you mean I have to derive my own CArray class? isn't another way I mean another array class that can do the trick! thanks
-
done :)
Probably Cédric's guess [^] is right. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi! :) I guess you are right! you mean I have to derive my own CArray class? isn't another way I mean another array class that can do the trick! thanks
Electronic75 wrote:
you mean I have to derive my own CArray class
No, I mean you have to provide a =operator and a copy constructor for your structure. Inside those, instead of simply assigning the arrays, like this:
mystruct::myStruct(const mystruct& copy)
{
array1 = copy.array1;
}you will need to copy the content of the array by iterating over it.
Electronic75 wrote:
isn't another way I mean another array class that can do the trick!
std::string or std::list maybe ? But you have to be carefull of what is inside those arrays. If you store pointers, you will have a copy of the original pointer pointing at the same memory location, so you should only delete one of them (so, it's a bit dangerous).
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
Electronic75 wrote:
you mean I have to derive my own CArray class
No, I mean you have to provide a =operator and a copy constructor for your structure. Inside those, instead of simply assigning the arrays, like this:
mystruct::myStruct(const mystruct& copy)
{
array1 = copy.array1;
}you will need to copy the content of the array by iterating over it.
Electronic75 wrote:
isn't another way I mean another array class that can do the trick!
std::string or std::list maybe ? But you have to be carefull of what is inside those arrays. If you store pointers, you will have a copy of the original pointer pointing at the same memory location, so you should only delete one of them (so, it's a bit dangerous).
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++Thanks a lot Cedric, It worked pretty much OK:cool::rose: