Re: CArray
"Giovanni Dicanio" <giovanni.dicanio@invalid.it> wrote in message
news:efai7qvHIHA.5208@TK2MSFTNGP04.phx.gbl...
Dave: you correctly answered OP's question, which asked about CArray.
What I don't like about CArray, is the fact that I need to write copy ctor
and operator=.
I write a copy constructor and an = operator for just about every class I
write as a matter of course. Even if not strictly needed. OK I confess
I'm a control freak :-)
I think that if the OP uses std::vector, there is a default copy mechanism
implemented, i.e. copy ctor and operator= don't need to be explicitly
defined.
So, I would do something like this:
<code>
typedef std::vector< CString > StringArray;
typedef std::vector< StringArray > StringMatrix;
StringMatrix strings;
</code>
I'd probably use something like that too - because I have seen the source
code for CArray :-)
But I'd prefer
class CMyArray1 :: std::vector< CString >
{
}
class CMyArray2 :: std::vector< CMyArray1 >
{
}
because usually, sooner or later, I don't want to be limited to the methods
of std::vector and this opens the way for me to add my own.
or better, I would implement the 2D matrix using a single array (1D), but
I would define a pair of methods like Get and Set, which take in input two
integers (row and column) and access in read/write the given string
element.
...
Yes.
.....
The fact that Set returns a reference to the object, allows chained call,
e.g.:
aStringMatrix.Set( 1, 3, _T("Hello") ).Set( 2, 5, _T("World") ).Set( 0,
3, _T("Ciao") );
There is such a thing as codes being too clever for their own good <vbg>.
I know; I have written a few :-)
Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mozartists/mailinglist.htm