 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
LEF Guest
|
Posted: Wed Apr 27, 2005 3:03 pm Post subject: Return Type |
|
|
Hello All,
My apologies if this question is in the FAQ, however, I looked for the FAQ
but couldn't find it. Direction to it would be appreciated. My question is
very simple, can a class have as a return type for one it's methods the type
the class defines? Probably not clear, an example:
class example {
public:
example testfn();
};
example example::testfn() {
}
Is that valid?
Thanks.
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Wed Apr 27, 2005 3:19 pm Post subject: Re: Return Type |
|
|
LEF wrote:
| Quote: | My apologies if this question is in the FAQ, however, I looked for the FAQ
but couldn't find it. Direction to it would be appreciated. My question is
very simple, can a class have as a return type for one it's methods the type
the class defines? Probably not clear, an example:
class example {
public:
example testfn();
};
example example::testfn() {
}
Is that valid?
|
Absolutely. Do you experience any problems?
V
|
|
| Back to top |
|
 |
Chris ( Val ) Guest
|
Posted: Thu Apr 28, 2005 11:00 am Post subject: Re: Return Type |
|
|
"LEF" <lef204 (AT) mts (DOT) net> wrote
| Quote: | Hello All,
My apologies if this question is in the FAQ, however, I looked for the FAQ
but couldn't find it. Direction to it would be appreciated. My question is
very simple, can a class have as a return type for one it's methods the type
the class defines? Probably not clear, an example:
class example {
public:
example testfn();
};
example example::testfn() {
}
Is that valid?
|
As long as you actually return an object of type
'example', then yes - Not only is it valid, it is
a commonly used construct.
Cheers,
Chris Val
|
|
| Back to top |
|
 |
Samee Zahur Guest
|
Posted: Sat Apr 30, 2005 10:11 am Post subject: Re: Return Type |
|
|
That IS how it is mostly done. But to be able to return an object of
type 'example' from any function (member or not) by value, you must
have a valid copy constructor (explicitly defined or compiler
generated). If you don't know what a copy-ctor is, forget what I just
said :)
Samee
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|