473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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 ;
};
Apr 26 '07 #1
3 1176
2b|!2b==? wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 26 '07 #2


Victor Bazarov wrote:
2b|!2b==? wrote:
>>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
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 ...
Apr 26 '07 #3
2b|!2b==? wrote:
[..] 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 26 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jason Evans | last post by:
Hi All, I am writing my own implementation of queue via a linked list, note not a LinkedList, and was running into trouble with the clone method. I was wondering if anyone could point out some...
0
by: r035198x | last post by:
Overriding therefore allows you to use the same method name to refer to differently implemented methods. Here is an example using the famous shapes example. class Shape { public Shape()...
5
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is...
0
by: r035198x | last post by:
Inheritance We have already covered one important concept of object-oriented programming, namely encapsulation, in the previous article. These articles are not articles on object oriented...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.