Pointers to member functions - quick Q

This is a discussion on Pointers to member functions - quick Q within the C++ Programming forums, part of the General Programming Boards category; When I use GCC with Dev-C++, it gets interpreted as MyClass(*)(). Either way, the compiler changes the meaning of the ...

  1. #16

    Join Date
    Apr 2008
    Location
    USA
    Posts
    76
    When I use GCC with Dev-C++, it gets interpreted as MyClass(*)(). Either way, the compiler changes the meaning of the code significantly (without telling you) from something that's semantically illegal (functions can't be passed by value) to something that's legal but very different in meaning.
    Last edited by rudyman; 09-01-2008 at 11:02 AM. Reason: typo

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,409
    Either way, the compiler changes the meaning of the code significantly (without telling you) from something that's semantically illegal (functions can't be passed by value) to something that's legal but very different in meaning.
    More like the code is interpreted in a way that the author may not expect, so the author is actually expressing a meaning contrary to his or her intention.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    The larch
    Join Date
    May 2006
    Posts
    3,573
    It looks you are right.

    Isn't this feature inherited from C where the two following lines declare the same thing (and omit the name p, since a function can have unnamed arguments)?

    Code:
    void foo(int (*p)());
    void foo(int p());
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #19

    Join Date
    Apr 2008
    Location
    USA
    Posts
    76
    Yeah. And the point I'm trying to make is, that feature is useless aside from syntactic sugar and it only causes ambiguity and misinterpretation. If the compiler didn't do that, it would see that the function declarator was illegal and would (hopefully) treat it as a constructor instead.

    But I guess compatibility deserves higher priority.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Modules and Member Functions
    By arrgh in forum C++ Programming
    Replies: 2
    Last Post: 05-07-2008, 02:46 AM
  2. issue with member functions
    By Chaplin27 in forum C++ Programming
    Replies: 4
    Last Post: 09-27-2006, 09:18 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 05:58 PM
  5. Replies: 4
    Last Post: 11-23-2003, 06:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21