Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6544731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:30:03+00:00 2026-05-25T11:30:03+00:00

What’s the difference between typedef void (&FunctionTypeR)(); vs typedef void (FunctionType)(); Is the second

  • 0

What’s the difference between

typedef void (&FunctionTypeR)();

vs

typedef void (FunctionType)();

Is the second also a reference to function? Is FunctionTypeR equivalent to FunctionType& when used as the type of an argument?

For

void foo(FunctionType bar)

Does the runtime makes a copy of the argument bar (a function) when foo is invoked?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:30:04+00:00Added an answer on May 25, 2026 at 11:30 am

    The difference is that you cannot create objects of function type, but you can create of objects of function pointer type, and function reference type.

    That means if you’ve a function, say f() as:

     void f(){}
    

    then here is what you can do, and what you cannot do:

    FunctionType  fun1 = f; //error - cannot create object of function type
    FunctionType *fun2 = f; //ok 
    FunctionTypeR fun3 = f; //ok
    

    Test code:

    typedef void (&FunctionTypeR)();
    typedef void FunctionType();
    
    void f(){}
    
    int main() {
            FunctionType  fun1 = f; //error - cannot create object of function type
            FunctionType *fun2 = f; //ok 
            FunctionTypeR fun3 = f; //ok
            return 0;
    }
    

    Now see the compilation error (and warnings):

     prog.cpp: In function ‘int main()’:
     prog.cpp:7: error: function ‘void fun1()’ is initialized like a variable
     prog.cpp:8: warning: unused variable ‘fun2’
     prog.cpp:9: warning: unused variable ‘fun3’
    

    Online demo : http://ideone.com/hpTEv


    However, if you use FunctionType (which is a function type) in a function parameter list as:

    void foo(FunctionType bar);
    

    then it’s equivalent to

    void foo(FunctionType * bar);
    

    That means, no matter what you write, you can call the function using bar as:

       bar();  //ok
     (*bar)(); //ok 
    

    That is, you can write this:

    void h(FunctionType fun) { fun(); }
    void g(FunctionType fun) { (*fun)(); }
    

    Demo : http://ideone.com/kwUE9

    This is due to function type to function pointer type adjustment; that is, the function type is adjusted to become a pointer to function type:

    Function type     |  Function pointer type (adjusted type)
       void ()        |     void (*)()
       void (int)     |     void (*)(int)
       int  (int,int) |     int  (*)(int,int)
       ....           |      ... so on
    

    The C++03 Standard says in §13.1/3,

    Parameter declarations that differ only in that one is a function type and the other is a pointer to the same function type are equivalent. That is, the function type is adjusted to become a pointer to function type (8.3.5).

    [Example:
        void h(int());
        void h(int (*)()); // redeclaration of h(int())
        void h(int x()) { } // definition of h(int())
        void h(int (*x)()) { } // ill-formed: redefinition of h(int())
    ]
    

    And if you use `FunctionTypeR (which is a function reference type) as:

    void foo(FunctionTypeR bar);
    

    then it’s equivalent to:

    void foo(FunctionType * & bar);
    

    And,

    void h(FunctionTypeR fun) { fun(); }
    void g(FunctionTypeR fun) { (*fun)(); }
    

    Demo : http://ideone.com/SmtQv


    Interesting part…

    You can use FunctionType to declare a function (but not to define it).

    For example,

    struct A
    {
       //member function declaration. 
        FunctionType f; //equivalent to : void f();
    };
    
    void A::f() //definition
    {
      std::cout << "haha" << std::endl;
    }
    
    //forward declaration
    FunctionType h; //equivalent to : void h();
    
    int main() {
            A a;
            a.f(); //call member function
            h();   //call non-member function
    }
    
    void h() //definition goes below main()
    {
       std::cout <<"hmmm.." << std::endl;
    }
    

    Demo : http://ideone.com/W4ED2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I used javascript for loading a picture on my website depending on which small
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
i got an object with contents of html markup in it, for example: string
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm looking for suggestions for debugging... If you view this site in Firefox or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.