C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Return Type

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
LEF
Guest





PostPosted: Wed Apr 27, 2005 3:03 pm    Post subject: Return Type Reply with 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?

Thanks.


Back to top
Victor Bazarov
Guest





PostPosted: Wed Apr 27, 2005 3:19 pm    Post subject: Re: Return Type Reply with quote



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





PostPosted: Thu Apr 28, 2005 11:00 am    Post subject: Re: Return Type Reply with quote




"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





PostPosted: Sat Apr 30, 2005 10:11 am    Post subject: Re: Return Type Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.