C++ declarative syntax

Discussion in 'C++' started by muler, Apr 12, 2011.

  1. muler

    muler Guest

    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,
    muler, Apr 12, 2011
    #1
    1. Advertising

  2. muler

    SG Guest

    On 12 Apr., 13:37, muler <> 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
    SG, Apr 12, 2011
    #2
    1. Advertising

  3. muler

    muler Guest

    On Apr 12, 2:51 pm, SG <> wrote:
    > On 12 Apr., 13:37, muler <> 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!
    muler, Apr 12, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MS Newsgroups

    Declarative Security in ASP .net

    MS Newsgroups, Oct 17, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    436
    Natty Gur
    Oct 19, 2003
  2. =?Utf-8?B?VGltbQ==?=
    Replies:
    11
    Views:
    3,587
    Angna
    Jun 29, 2006
  3. drop
    Replies:
    0
    Views:
    276
  4. Nathan Sokalski
    Replies:
    0
    Views:
    284
    Nathan Sokalski
    Apr 2, 2008
  5. muler

    C++ declarative syntax

    muler, Apr 12, 2011, in forum: C++
    Replies:
    3
    Views:
    268
    Victor Bazarov
    Apr 12, 2011
Loading...

Share This Page