Hi All,

Suppose I have a class of my own, CVCEditBox and I overload a few operators
like this:

class CVCEditBox : public CStatic

{

....
CVCEditBox operator+ (const CVCEditBox& TheString) const;
...
}

And then, the implementation of this operator would be:

CVCEditBox CVCEditBox::operator+(const CVCEditBox& TheString) const

{

return CVCEditBox((CString) SomeString);

}

By the way, I do have an argument constructor that takes a CString..

The question is, is there any problem if I do the overloading this way ?
[returning the constructor of the object] It seems to work but I am
wondering if I should do it differently (maybe a more efficient way .. it
seems to me that returning the constructor rathern than a combination of
*this / CVCEditBox& uses more memory since it does a copy/create a new
object ?!]

Thanks in advance,
Marius

Re: overloaded operator by Lucas

Lucas
Mon Dec 15 13:29:27 CST 2003

This is the correct way to do it, because, if you do

CVCEditBox a, b, c;
c = a + b;

you do not want to change a.

Of course, you can always implent operator+=

Lucas/

"Marius" <prisasm@h0tmail.remove-this-n-make-zero-o.com> wrote in message
news:u5iSLuzwDHA.4060@TK2MSFTNGP11.phx.gbl...
> Hi All,
>
> Suppose I have a class of my own, CVCEditBox and I overload a few
operators
> like this:
>
> class CVCEditBox : public CStatic
>
> {
>
> ....
> CVCEditBox operator+ (const CVCEditBox& TheString) const;
> ...
> }
>
> And then, the implementation of this operator would be:
>
> CVCEditBox CVCEditBox::operator+(const CVCEditBox& TheString) const
>
> {
>
> return CVCEditBox((CString) SomeString);
>
> }
>
> By the way, I do have an argument constructor that takes a CString..
>
> The question is, is there any problem if I do the overloading this way ?
> [returning the constructor of the object] It seems to work but I am
> wondering if I should do it differently (maybe a more efficient way .. it
> seems to me that returning the constructor rathern than a combination of
> *this / CVCEditBox& uses more memory since it does a copy/create a new
> object ?!]
>
> Thanks in advance,
> Marius
>
>
>
>
>