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 

quick questions

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





PostPosted: Mon Sep 11, 2006 9:10 am    Post subject: quick questions Reply with quote



i haven't seen these in any tutorials or anything i've read so i'm
wondering if someone could tell me what they're called so i can
research them.

i've only seen functions like

animal.make_noise("fart");

but the other day i ran into something like

animal.sounds().make_noise("fart");

is there a name for calling multiple functions like this?
Back to top
Stuart Redmann
Guest





PostPosted: Mon Sep 11, 2006 9:10 am    Post subject: Re: quick questions Reply with quote



Steve Chow wrote:

Quote:
i haven't seen these in any tutorials or anything i've read so i'm
wondering if someone could tell me what they're called so i can
research them.

i've only seen functions like

animal.make_noise("fart");

but the other day i ran into something like

animal.sounds().make_noise("fart");

is there a name for calling multiple functions like this?


It's not that two methods sounds () and make_noise (...) are called for
the animal object, but rather only sounds (). This method would return
another object that we don't know (at least I guess this, else the code
wouldn't compile or make sense). For this object the method
make_noise(...) is called.

As far as I know there is no special name for such a mechanism. If
sounds () were a method that returned the animal object, this would be
called 'call chaining'. This is used for reading and writing formatted
data with IO streams. Consider for example operator<< for streams. Using
this you can write statements like
cout << "Some text" << iSomeNumber << "AnotherText";
This statement could be written as
cout << "Some text";
cout << iSomeNumber;
cout << "AnotherText";
Since it would be tedious to repeat 'cout << ' over and over again, the
operator<< for streams should output the argument and return the stream.

Regards,
Stuart
Back to top
Jens Theisen
Guest





PostPosted: Mon Sep 11, 2006 9:10 am    Post subject: Re: quick questions Reply with quote



"Steve Chow" <msweaksauce (AT) hotmail (DOT) com> writes:

Quote:
animal.sounds().make_noise("fart");

is there a name for calling multiple functions like this?

No, but there is also nothing special about it.

animial has a member function sounds, which returns some object x
which has in turn a member function make_noise taking a string.

The above line could happily be java with the same semantics.

Cheers,

Jens
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.