Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C++ declarative syntax

Reply
Thread Tools

C++ declarative syntax

 
 
muler
Guest
Posts: n/a
 
      04-12-2011
Q: Write a function declaration that takes a double argument and
returns a pointer to a function that takes an int argument and
returns
a pointer to char without using a typedef?

using a typedef, it's easy:

typedef char* (*Ptr_func)(int);
Ptr_func Func(double);

Thanks,
 
Reply With Quote
 
 
 
 
SG
Guest
Posts: n/a
 
      04-12-2011
On 12 Apr., 13:37, muler <(E-Mail Removed)> wrote:
> Q: Write a function declaration that takes a double argument and
> returns a pointer to a function that takes an int argument and
> returns
> a pointer to char without using a typedef?
>
> using a typedef, it's easy:
>
> typedef char* (*Ptr_func)(int);
> Ptr_func Func(double);


char *(*Func(double))(int);

Not that I would write something like this without a typedef in real
code. Basically, you have a type on the left side -- here: char -- and
a declarator on the right side -- here: *(*Func(double))(int). You
can think of the declarator like an expression and the type infront of
the declarator spedifies the type of this expression. The only
difference between declarator and expression that comes to my mind
right now is that the unary ampersand has a different meaning. The
unary ampersand is an address operator in an expression and a
"reference declarator" in a declarator. With this understanding, you
can read the above declaration "inside out".

SG
 
Reply With Quote
 
 
 
 
muler
Guest
Posts: n/a
 
      04-12-2011
On Apr 12, 2:51*pm, SG <(E-Mail Removed)> wrote:
> On 12 Apr., 13:37, muler <(E-Mail Removed)> wrote:
>
> > Q: Write a function declaration that takes a double argument and
> > returns a pointer to a function that takes an int argument and
> > returns
> > a pointer to char without using a typedef?

>
> > using a typedef, it's easy:

>
> > typedef char* (*Ptr_func)(int);
> > Ptr_func Func(double);

>
> * char *(*Func(double))(int);
>
> Not that I would write something like this without a typedef in real
> code. Basically, you have a type on the left side -- here: char -- and
> a declarator on the right side *-- here: *(*Func(double))(int). You
> can think of the declarator like an expression and the type infront of
> the declarator spedifies the type of this expression. The only
> difference between declarator and expression that comes to my mind
> right now is that the unary ampersand has a different meaning. The
> unary ampersand is an address operator in an expression and a
> "reference declarator" in a declarator. With this understanding, you
> can read the above declaration "inside out".
>
> SG


nice!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ declarative syntax muler C++ 3 04-12-2011 02:20 PM
Declarative syntax for different borders in server controls Nathan Sokalski ASP .Net 0 04-02-2008 05:41 AM
Implicit Conversion with Declarative syntax drop ASP .Net 0 09-13-2007 07:29 PM
Interdependent DropDownLists (with declarative data binding) =?Utf-8?B?VGltbQ==?= ASP .Net 11 06-29-2006 06:49 AM
Declarative Security in ASP .net MS Newsgroups ASP .Net 1 10-19-2003 07:21 AM



Advertisments