From: Giovanni Dicanio on
"Ru" <ruspatil(a)gmail.com> ha scritto nel messaggio
news:7c2075d5-fec0-4e15-a325-552dcdb31d2d(a)g1g2000pra.googlegroups.com...

> Thanks Giovanni.
> Understood the reason. I will use std::vector instead.

You are welcome.

As a side note (and not directly related to your original question), I think
that you may want to make your coding style more coherent, in a sense that
your CDrawElement structure has two data members, but you used the 'm_'
prefix only for one of them, i.e. 'm_bChildren':

struct CDrawElement
{
bool m_bChildren;
CArray <int, int> ptArray;
};

I would suggest you to either use the 'm_' prefix for both data members
(e.g. m_bChildren and m_ptArray), or not use the 'm_' prefix at all.

FWIW, I would get rid of the 'm_' prefix in the above case [I would consider
the 'm_' prefix for private/protected data members of full-fledged classes]
and also get rid of 'b' and 'pt' prefixes...
The 'b' prefix is kind of ambiguous, in fact it often indicates BYTE, e.g.

CryptBinaryToString Function
http://msdn.microsoft.com/en-us/library/aa379887%28VS.85%29.aspx

const BYTE *pbBinary : (p)ointer to an array of (b)ytes
DWORD cbBinary : (c)ount of (b)ytes

(Instead you used it for a 'bool'.)
I would rename the 'm_bChildren' data member something like:

bool hasChildren;

I find that more clear and more readable than 'm_bChildren'.

And if the 'ptArray' is an array of points, I would just name it like:

std::vector<int> points;

Moreover, I would use the 'C' prefix for full-fledged classes (i.e. things
with private data members, public accessors, member functions, etc.), not
for simple structures (containing only some public data members), so I would
write:

struct DrawElement
{
bool hasChildren;
std::vector<int> points;
};


My 2 cents,
Giovanni



From: Giovanni Dicanio on
"Goran" <goran.pusic(a)gmail.com> ha scritto nel messaggio
news:0308908d-3b51-4792-b903-d9c13e4b940c(a)m26g2000yqb.googlegroups.com...

> You can also write your own assignment operator, e.g.
>
> CDrawElement& CDrawElement::operator=(const CDrawElement& rhs)

I'm not sure, but I think that if a custom implementation of operator= is
written, also copy constructor should be.

> {
> if (this != &rhs)
> {
> ptArray.Copy(rhs.ptArray); // Copy is MFC container equivalent for
> operator= ;-)

I would prefer using an already-copiable container like std::vector (or
other) than writing a custom operator= and copy ctor implementation, IMHO.

Giovanni