|
-
December 18th, 2007, 12:41 PM
#1
Problem with CArray inside a structure
Hi all,
I have a Structure defined as follows
Code:
struct StationGroup
{
CString cStrGroupName;
CArray<CString,CString&> cArryStationList;
};
Which consist of a CArray of CString, Now i need to make a CArray of the structur, which i did as follows
Code:
CArray<StationGroup,StationGroup&> m_cArryGroupList;
when i am adding a single object of the structure "StationGroup" to the CArray "m_cArryGroupList" as follows
Code:
m_cArryGroupList.Add((StationGroup&)sTructStationGroup);
I get an error as follows and it no way indicates that the error is in the above line, but if i comment this line, Then i dont get the following error
Code:
PIConfigComm.cpp
c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxtempl.h(272) : error C2248: 'CObject::operator =' : cannot access private member declared in class 'CObject'
c:\program files\microsoft visual studio 8\vc\atlmfc\include\afx.h(554) : see declaration of 'CObject::operator ='
c:\program files\microsoft visual studio 8\vc\atlmfc\include\afx.h(524) : see declaration of 'CObject'
This diagnostic occurred in the compiler generated function 'CArray<TYPE,ARG_TYPE> &CArray<TYPE,ARG_TYPE>::operator =(const CArray<TYPE,ARG_TYPE> &)'
with
[
TYPE=CString,
ARG_TYPE=CString &
]
where CPIConfigComm is the name of the class
Can some one please help me....
Thanks and Regards
RK
Last edited by poshyradha; December 18th, 2007 at 12:51 PM.
Reason: Just now learned to include code tag, so tried implementing
-
December 18th, 2007, 12:44 PM
#2
Re: Problem with CArray inside a structure
see declaration of 'CObject: perator ='
It was originally like this --- [see declaration of 'CObject : : operator =']
the Scope resolution operator was interrepted as smiley
-
December 18th, 2007, 12:50 PM
#3
Re: Problem with CArray inside a structure
You can use std::vector<CString> instead of CArray and avoid these problems.
Code:
#include <vector>
struct StationGroup
{
CString cStrGroupName;
std::vector<CString> cArryStationList; // now structure can be copied
};
Regards,
Paul McKenzie
-
December 18th, 2007, 12:58 PM
#4
Re: Problem with CArray inside a structure
Thanks Paul,
Just now trying to implement.
as I dont know the addition and delition and manupulating operation , I will let you know once I get trough
By the way can you tell me what the problem with the previous implementation? Just a curiosity to learn :-)
Thanks and Regards
RK
-
December 18th, 2007, 01:13 PM
#5
Re: Problem with CArray inside a structure
CArray does not have copy semantics (it has a private copy
constructor and assignment operator). To put objects of
type StationGroup into a CArray, StationGroup must be copyable.
Which means every member of StationGroup must be copyable.
You can do one of the following:
1) use std::vector as Paul mentioned (that is what I would do)
2) Add copy constructor and assignment operator to StationGroup
3) derive from CArray and add copy semantics to it
see http://www.codeguru.com/forum/showthread.php?t=351440
-
December 18th, 2007, 01:16 PM
#6
Re: Problem with CArray inside a structure
Dear philip
Thanks a lot for the explanation [ ]
Regards
RK
-
December 18th, 2007, 10:12 PM
#7
Re: Problem with CArray inside a structure
Why are using CArray<CString,CString&> cArryStationList;
You can use std::vector as others suggested. Or alternatively you can use CStringList. Look MSDN documentation for the usage of CStringList MFC class.
If there is no love sun won't shine
-
December 18th, 2007, 10:49 PM
#8
Re: Problem with CArray inside a structure
 Originally Posted by miteshpandey
Or alternatively you can use CStringList. Look MSDN documentation for the usage of CStringList MFC class.
What would be the point of using CStringList ?
-
December 18th, 2007, 10:49 PM
#9
Re: Problem with CArray inside a structure
As Philip said implement a default constructor, Copy Constructor and assignment operator in your structure.
-
December 18th, 2007, 11:39 PM
#10
 Originally Posted by Philip Nicoletti
What would be the point of using CStringList ?
Ah! sorry probably CStringArray then.
He wants to store CString in a container isn't it?
If there is no love sun won't shine
-
December 18th, 2007, 11:44 PM
#11
Re: Problem with CArray inside a structure
Oops, sorry..........
My mind was more concentrated what was inside the struct rather than the struct itself.
Thanks for reminding.
If there is no love sun won't shine
-
December 19th, 2007, 03:33 AM
#12
Re: Problem with CArray inside a structure
Let me brief the purpose of my usage.
I have a list of Group names each group has a group name and a list of station
[i am not explaining what is group and station as it is purely business terms not a technical name]
so i made a structure with CString and a cstring array where the CString will contain the the group name and the cstring array will contain the list of stations.
after wich i will againg have a carry of the structure and store all the list of group into that array....
-
December 19th, 2007, 08:31 AM
#13
Re: Problem with CArray inside a structure
There are a number of designs that you can use. How you use the
data would determine which one is best.
In general, the design that you have chosen is fine. You just need
to make sure that StationGroup objects are copyable.
Other designs:
1) a map conatiner, with the key being the group name and the
value being the cArryStationList
2) a multimap container (which allows multiple values for each key).
Again, the group name would be the key and the values would be
the Station list names associated with that name.
-
December 19th, 2007, 09:39 AM
#14
Re: Problem with CArray inside a structure
Hi Philip,
Thanks for the suggestion,
Let me try that, as i mentioned earlier being new to Visual C++ i learning now. Will try this method and let me come back if at all i have any other complexcities in doing so.
-
December 19th, 2007, 09:52 AM
#15
Re: Problem with CArray inside a structure
 Originally Posted by poshyradha
Hi Philip,
Thanks for the suggestion,
Let me try that, as i mentioned earlier being new to Visual C++
Note that Visual C++ is just a compiler brand from Microsoft, it is not the language. The language is called just C++, and what Philip mentioned to you (as well as me mentioning std::vector) are general C++ classes and solutions that can be used with any ANSI compliant C++ compiler, not just Visual C++.
So what you're learning right now with respect to this thread is C++, and is not specific to the Visual C++ compiler.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|