CArray template class
-
does CMyStruct have an "operator =" member ? looks like that's what the compiler wants. have you considered std::vector instead of CArray? overall, std::vector is a nicer way to deal with an array of things. -c
Alcohol is the anesthesia by which we endure the operation of life. -- George Bernard Shaw
hi there, just wanted to let you'll know: When i remove the CStringArray from the structure it works!
-
hi there, just wanted to let you'll know: When i remove the CStringArray from the structure it works!
This is because of CStringArray has no "=" operator. Best regards Holger Persch
-
This is because of CStringArray has no "=" operator. Best regards Holger Persch
OK thats fine, but what happens when I **NEED** a CStringArray in my structure. (Right now i have replaced the CStringArray by a char**) but thats not very elegant!)
-
OK thats fine, but what happens when I **NEED** a CStringArray in my structure. (Right now i have replaced the CStringArray by a char**) but thats not very elegant!)
then you need to write an "=" operator for your struct. in it, you'll copy all the data items from the input struct to "this". -c
Alcohol is the anesthesia by which we endure the operation of life. -- George Bernard Shaw
-
then you need to write an "=" operator for your struct. in it, you'll copy all the data items from the input struct to "this". -c
Alcohol is the anesthesia by which we endure the operation of life. -- George Bernard Shaw
Do you mean implementing a = operator that copies from one CStringArray into another. P.S:I say this, because i am now using a statically allocated char[][], thereby eliminating the need for copying!
-
OK thats fine, but what happens when I **NEED** a CStringArray in my structure. (Right now i have replaced the CStringArray by a char**) but thats not very elegant!)
The "=" operator can look like this:
class CMyClass
{
.
.
.const CMyClass &operator =(const CMyClass &src) { m\_String = src.m\_String; m\_StringArray.RemoveAll(); m\_StringArray.Append(src.m\_StringArray); m\_StringArray.FreeExtra(); return \*this; }
public:
CString m_String;
CStringArray m_StringArray;
};Best regards Holger Persch
-
The "=" operator can look like this:
class CMyClass
{
.
.
.const CMyClass &operator =(const CMyClass &src) { m\_String = src.m\_String; m\_StringArray.RemoveAll(); m\_StringArray.Append(src.m\_StringArray); m\_StringArray.FreeExtra(); return \*this; }
public:
CString m_String;
CStringArray m_StringArray;
};Best regards Holger Persch
Thanks so much for this Holger, that was very kind of you.
-
Do you mean implementing a = operator that copies from one CStringArray into another. P.S:I say this, because i am now using a statically allocated char[][], thereby eliminating the need for copying!
Yes - you need to impliment operator = for CStringArray, as Chris has already said twice now. As he has also said, the MFC container classes are plain ugly compared to STL, and std::vector would solve all of these problems as well as opening up a whole world of elegant container design to you. Christian Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
-
The "=" operator can look like this:
class CMyClass
{
.
.
.const CMyClass &operator =(const CMyClass &src) { m\_String = src.m\_String; m\_StringArray.RemoveAll(); m\_StringArray.Append(src.m\_StringArray); m\_StringArray.FreeExtra(); return \*this; }
public:
CString m_String;
CStringArray m_StringArray;
};Best regards Holger Persch
Is there any reason for which you prefer RemoveAll/Append/FreeExtra over CStringArray::Copy? Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
-
Is there any reason for which you prefer RemoveAll/Append/FreeExtra over CStringArray::Copy? Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
No, i have just not recognized that there exists a copy method :-O. Best regards Holger Persch