quick question on using this keyword in 'clone' method ..

2

2b|!2b==?

Is this legal ?


MyClass& MyClass::Clone() const
{
//this should invoke the copy ctor ...
//but can I reference an object within itself ?
MyClass* mc = new MyClass(*this);
return *mc ;
};
 
V

Victor Bazarov

2b|!2b==? said:
Is this legal ?

Seems acceptable. Why?
MyClass& MyClass::Clone() const
{
//this should invoke the copy ctor ...

And it hopefully does.
//but can I reference an object within itself ?

What do you mean by that? Why wouldn't you be able to?
After all, that's what the 'this' is for.
MyClass* mc = new MyClass(*this);
return *mc ;
};

The trailing semicolon here is most likely illegal.

V
 
2

2b|!2b==?

Victor said:
Seems acceptable. Why?




And it hopefully does.




What do you mean by that? Why wouldn't you be able to?
After all, that's what the 'this' is for.




The trailing semicolon here is most likely illegal.

V

Erm, ill-posed question - sorry guys, I figured it out myself later. I
was getting myself confused about something entirely different - the
class I am using is a lot more "involved" than the trite MyClass I used
in the example - and I ended up getting myself confused. I think its
time I called it a day - been behind this screen for too long ...
 
V

Victor Bazarov

2b|!2b==? said:
[..] I think
its time I called it a day - been behind this screen for too long ...

It definitely sounds like it (now that you've mentioned your
position in relation to that screen -- I usually spend my days
*in front* of mine) <g>

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,298
Messages
2,571,540
Members
48,275
Latest member
tetedenuit01

Latest Threads

Top