Thread: Pointers to member functions - quick Q

  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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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.

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, 06:58 PM
  5. Replies: 4
    Last Post: 11-23-2003, 07:15 AM