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

composition of declarators

I saw an exaple in the c++ standard(clause 6.8),

-------------------------------------------------------
struct T1 {
T1 operator ()( int x ) { return T1(x ); }
int operator =( int x ) { return x; }
T1(int ) { }
};
struct T2 { T2(int ){ } };
int a , (*(* b)( T2 ))( int ), c , d;
void ff ()
{
T1(a) = 3 ,
(*(* b)( T2(c )))( int(d )); // AA
}
--------------------------------------------

I am confused that the declaration at the line AA is valid.
Then, what's the meaning of this declaration? Thank in advance.

Apr 24 '07 #1
4 1216
ssailor wrote:
I saw an exaple in the c++ standard(clause 6.8),

-------------------------------------------------------
struct T1 {
T1 operator ()( int x ) { return T1(x ); }
int operator =( int x ) { return x; }
T1(int ) { }
};
struct T2 { T2(int ){ } };
int a , (*(* b)( T2 ))( int ), c , d;
void ff ()
{
T1(a) = 3 ,
(*(* b)( T2(c )))( int(d )); // AA
}
--------------------------------------------

I am confused that the declaration at the line AA is valid.
It is.
Then, what's the meaning of this declaration? Thank in advance.
The second part of the declaration declares 'b' to be a pointer
to a function that takes one argument of type 'int' and returns
a pointer to a function that takes one argument of type T2 and
returns T1. 'c' and 'd' are names of the formal arguments and
do not add meaning to the declaration. The fact that they are
in parentheses does not matter.

In the example in the subclause 6.8 of the Standard the
declaration of 'b' is preceded by another declaration of 'T2'
which masks the type name, thus making parsing of the 'b'
declaration improper, and the code ill-formed. That's at least
AIUI. No diagnostic is required, though. Online trial of
Comeau compiles either code without a problem.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 24 '07 #2
Victor Bazarov Wrote:
'c' and 'd' are names of the formal arguments and
do not add meaning to the declaration. The fact that they are
in parentheses does not matter.
I took for granted that T2(c ), int(d ) were function-style casts
instead of function parameter declarations. This is the cause of my
confusion.

Thanks again for your clarification.

Apr 24 '07 #3

"Victor Bazarov" <v.********@comAcast.netwrote in message
news:Fc******************************@comcast.com. ..
ssailor wrote:
>I saw an exaple in the c++ standard(clause 6.8),

-------------------------------------------------------
struct T1 {
T1 operator ()( int x ) { return T1(x ); }
int operator =( int x ) { return x; }
T1(int ) { }
};
struct T2 { T2(int ){ } };
int a , (*(* b)( T2 ))( int ), c , d;
void ff ()
{
T1(a) = 3 ,
(*(* b)( T2(c )))( int(d )); // AA
}
--------------------------------------------

I am confused that the declaration at the line AA is valid.

It is.
>Then, what's the meaning of this declaration? Thank in advance.

The second part of the declaration declares 'b' to be a pointer
to a function that takes one argument of type 'int' and returns
a pointer to a function that takes one argument of type T2 and
returns T1.
Actually, it is the other way around: it is a function pointer taking a T2
and returning a pointer to a function taking an int and returning a T1.

The funny thing is, if you replace the comma on the previous line with a
semi-colon, it actually becomes a double function call: first on the
function pointed to by the earlier defined 'b', passing a T2 constructed out
of c, and another function call on the function returned by b(), passing an
int constructed out of d)

- Sylvester Hesp
Apr 24 '07 #4
Sylvester Hesp wrote:
"Victor Bazarov" <v.********@comAcast.netwrote in message
news:Fc******************************@comcast.com. ..
>ssailor wrote:
>>I saw an exaple in the c++ standard(clause 6.8),

-------------------------------------------------------
struct T1 {
T1 operator ()( int x ) { return T1(x ); }
int operator =( int x ) { return x; }
T1(int ) { }
};
struct T2 { T2(int ){ } };
int a , (*(* b)( T2 ))( int ), c , d;
void ff ()
{
T1(a) = 3 ,
(*(* b)( T2(c )))( int(d )); // AA
}
--------------------------------------------

I am confused that the declaration at the line AA is valid.

It is.
>>Then, what's the meaning of this declaration? Thank in advance.

The second part of the declaration declares 'b' to be a pointer
to a function that takes one argument of type 'int' and returns
a pointer to a function that takes one argument of type T2 and
returns T1.

Actually, it is the other way around: it is a function pointer taking
a T2 and returning a pointer to a function taking an int and
returning a T1.
Right. My mistake.
>
The funny thing is, if you replace the comma on the previous line
with a semi-colon, it actually becomes a double function call: first
on the function pointed to by the earlier defined 'b', passing a T2
constructed out of c, and another function call on the function
returned by b(), passing an int constructed out of d)
The funnier thing is, if you drop 'T1' from the line above, the
entire statement becomes executable, assigning 3 to 'a' and then
calling 'b' and the other function as you described.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 24 '07 #5

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

Similar topics

4
by: fog | last post by:
Given: class A; and B "has-a" A. The composition relationship between A and B can be implemented in three ways: =================== # 1. class B {
7
by: preetam | last post by:
Hi, This question is more towards design than towards c++ details. By looking at books on design patterns and various google threads on the same topic, I see that composition is favoured to...
9
by: Code4u | last post by:
My colleagues and I have been discussing techniques for implementing interfaces in C++. We're looking for a mechanism similar to COM's QueryInterface, in which a certain types of objects can be...
4
by: cmrchs | last post by:
Hi, how do I implement aggregation and how composition in C# ? When I say : an Airplane has a Pilot then I use aggregation but when I say : an Airplane has a Cockpit then I use composition. How...
4
by: Frederik Vanderhaegen | last post by:
Hi, Can anyone explain me the difference between aggregation and composition? I know that they both are "whole-part" relationships and that composition parts are destroyed when the composition...
2
by: Gary Wessle | last post by:
Hi what is the difference "in code writing" between aggregation and composition? is the following correct? aggregation (life time of both objects are independent). class A{ /* ... */ };...
2
by: chandanlinster | last post by:
In K&R (page 210, A8), "declaration" is defined to be: declaration: declaration-specifiers init-declarators-list(opt); Later (3rd paragraph), it says that, "empty declarations are not...
3
by: jyck91 | last post by:
I want to get some ideas to organise a composition analyzer?? eg. frequencies of letters Thx for your suggestion
5
by: jyck91 | last post by:
Can anyone give me some ideas to organise a composition analyzer in C? It analyses an english composition. What functions should it include? eg. frequency of letter/ words thanks for help
4
by: Kay Schluehr | last post by:
As you know, there is no operator for function composition in Python. When you have two functions F and G and want to express the composition F o G you have to create a new closure lambda...
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
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...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.