473,378 Members | 1,334 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,378 software developers and data experts.

unfamilar C++ call syntax

I've seen this fragment of code used in the Boost libraries.
Can someone tell me what property of C++ this uses as I
have'nt seen it before.

I'm referring to the multiple () calls

is it similar to

desc.add_options().add_options("help","produce help
message").add_options("compression",po::value<int> (),"set compression
level");

??

// Declare the supported options.
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("compression", po::value<int>(), "set compression level")
;

Jul 22 '05 #1
2 1339
Mark wrote:
I've seen this fragment of code used in the Boost libraries.
Can someone tell me what property of C++ this uses as I
have'nt seen it before.

I'm referring to the multiple () calls

is it similar to

desc.add_options().add_options("help","produce help
message").add_options("compression",po::value<int> (),"set compression
level");

??

// Declare the supported options.
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("compression", po::value<int>(), "set compression level")
;


If a member function returns an object or a reference to an object, then
you can use the dot operator to access other members of that object.

struct A {
A& foo() { return *this; }
void bar() {}
};

int main() {
A a;

a.foo().bar(); // the same as ( a.foo() ).bar();
}

V
Jul 22 '05 #2
Mark wrote:
I've seen this fragment of code used in the Boost libraries.
Can someone tell me what property of C++ this uses as I
have'nt seen it before.

I'm referring to the multiple () calls

is it similar to

desc.add_options().add_options("help","produce help
message").add_options("compression",po::value<int> (),"set compression
level");
add_option() probably returns a reference to
'desc', making possible to chain the function calls.

class C
{
public:
C& f()
{
return *this;
}
};

int main()
{
C c;

c.f().f().f().f();
}
??

// Declare the supported options.
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("compression", po::value<int>(), "set compression level")
;


Same thing here, excepts that the object returned
is a function object (either a real function or a
class with operator() ).

class FO
{
public:
FO& operator() ()
{
return *this;
}
};

int main()
{
FO o;

o()()()()()();
}
Jonathan
Jul 22 '05 #3

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

Similar topics

3
by: ¤ Alias | last post by:
I have a function named getID3info (lvwDiscInfo.SelectedItem). What is the difference between getID3info (lvwDiscInfo.SelectedItem) and Call getID3info(lvwDiscInfo.SelectedItem) ?
4
by: John Z. Smith | last post by:
Hi, I want to subclass a class (more precisely, optparse.Option). that looks like class Option: def __init__(self, *opts, **attrs): do_something() I want to do something in my __init__...
66
by: Robert Brewer | last post by:
The J2 proposal is as complete as it will ever be. http://www.aminus.org/rbre/python/pydec.html The patch is nearly complete; only the __future__ declaration and some document tweaks remain....
23
by: Fabian Müller | last post by:
Hi all, my question is as follows: If have a class X and a class Y derived from X. Constructor of X is X(param1, param2) . Constructor of Y is Y(param1, ..., param4) .
15
by: Steve Jorgensen | last post by:
I'm looking for coding style opinions. It looks to me like most VB/VBA coders use the command-style syntax for calling subs or functions being treated as subs in a particular context ... Foo...
5
by: Amaryllis | last post by:
I'm trying to call a CL which is located on our AS400 from a Windows application. I've tried to code it in different ways, but I seem to get the same error every time. Does anyone have any clue...
5
by: Frederick Gotham | last post by:
If we have a simple class such as follows: #include <string> struct MyStruct { std::string member; MyStruct(unsigned const i) {
10
by: ravi | last post by:
Hi, i am a c++ programmer, now i want to learn programming in c also. so can anybody explain me the difference b/w call by reference and call by pointer (with example if possible).
9
by: parag_paul | last post by:
Hi all I am seeing the following code in one place standalone line in some function , { (void*) new (h) Class_Name(xip, virobj, type, true); } Does it make h an object of the Class_Name...
7
by: krishna | last post by:
What is the need of this syntax for initializing values, isn't this ambiguous to function call? e.g., int func_name(20); this looks like function call (of course not totally as there is no...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

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.