Like Tree2Likes
  • 1 Post By laserlight
  • 1 Post By Lesshardtofind

void (*)(int)

This is a discussion on void (*)(int) within the C++ Programming forums, part of the General Programming Boards category; Hey, I got an error I couldn't google. Following a tutorial I tried to roll the GLUT menu capabilities into ...

  1. #1
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407

    void (*)(int)

    Hey,

    I got an error I couldn't google. Following a tutorial I tried to roll the GLUT menu capabilities into a class that I could use in other programs later.
    Code:
    cannot convert ‘GlutMenu::MenuEvents’ from type ‘void (GlutMenu::)()’ to type ‘void (*)(int)’
    Best I can tell in english it means can't convert GlutMenu void to a void pointer int.

    I am not sure I know what a void pointer int is. The error was -fpermissive, but I stay away from doing that if I don't know why I'm doing it.

    Should I try typecasting?

    Thanks for your time!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    Basically, it looks like you are trying to convert a member function pointer to a pointer to a function that takes no arguments and returns void. This is most likely a mistake, and typecasting would probably just hide the error rather than fix it.
    Lesshardtofind likes this.
    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. #3
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    Yea it looks like the required function takes a different number of parameters than I set.

    6.1 glutCreateMenu

    The documentation that came with freeglut3-dev didn't show this page. I always look for something for 20 minutes then the answer shows up like 5 min after I post. ;o/

    Just to make sure I learn something out of this though does the compiler saying
    void (*) (int)
    mean it is a pointer to a void function that expects an int as an argument?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    Quote Originally Posted by Lesshardtofind
    Just to make sure I learn something out of this though does the compiler saying
    void (*) (int)
    mean it is a pointer to a void function that expects an int as an argument?
    Yes
    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

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    Remember that OpenGL is a C API. It knows nothing about C++ features such as classes and member functions!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    Yea I found out about that from a book I was reading. I want to do 3d graphics, but in no way do I want to start over with learning C. So I started setting up SFML (Simple and Fast Multimedia Library) which is written in c++ supports a lot of OOP concepts and still has much of the functionality of GLUT and SDL, but it is not as well established is the downside.

    You pointed out some of the ugly in SDL last week, and I would have to agree there are some downsides as it is written in C as well, it is not longer being updated and it comes with a lot of overhead. The hard thing to walk away from is its maturity. SDL with open GL will run on nearly anything from Windows to Wii.

    At this point I am experimenting with a lot of frameworks. To find out what I like and what I don't. I spent the last two days on glut only to find out you can't pass an argument to its render function so all draw coordinates have to be global variables or you have to have a global pointer that knows where everything else is. I really don't like either solution so I am going to test SFML.

    Thanks for the info Elysia.
    Last edited by Lesshardtofind; 12-31-2012 at 01:25 PM.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I usually wrap the SDL in a few of my own classes. It's not very hard. Also, libraries like SFML are likely based on the SDL, so if SDL is supported and there's a C compiler, SFML should work as well. But check the documentation about this, I don't know whether SFML is built entirely on the SDL or not.

    If you really want to use glut you can take pointers to static member functions, with a simple extern "C" wrapper that just calls the static function if you're having trouble with C/C++ linkage. This works well for C APIs like bullet that don't have many callbacks, I guess it would be somewhat painful but usable with glut.

    The nice thing about the SDL is you can use as much or as little of it as you want. A basic SDL program is very small and straightforward. When you want to do something like receive keyboard input it's just an extra switch statement... C++-ified however you prefer.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,258
    Also, libraries like SFML are likely based on the SDL, so if SDL is supported and there's a C compiler, SFML should work as well.
    O_o

    That doesn't make any sense.

    Why would any library likely be based on SDL?

    And no C++ library, without a C wrapper obviously, will work with only a C compiler regardless upon any libraries it may be built.

    Soma

  9. #9
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    SFML is a c++ library SDL is a C library. SFML is not built on top of SDL. SFML is slightly faster (up to 10x for some graphics operations) but lacks the maturity (not supported by near as many platforms), but is constantly updated and its lead developer maintains a forum to assist with the library. There are downsides and upsides to both.

    Just google SDL vs SFML.

  10. #10
    Registered User
    Join Date
    May 2009
    Posts
    2,572
    After 5 minutes of Goggling

    Looks like SFML may be based partly on GLEW.

    And, GLEW was likely influenced by GLX and SDL.

    Did not see SFML being based on SDL. But, did not look very deep.

    Edit: Think I found the source of the confusion from http://www.sfml-dev.org/features.php
    Can be used as a minimal, portable package to replace GLUT or SDL for windowing and input with OpenGL
    Tim S.
    Last edited by stahta01; 12-31-2012 at 05:25 PM.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: invalid conversion from 'const void*' to 'void*'
    By Wahidin Wahid in forum C++ Programming
    Replies: 10
    Last Post: 04-17-2012, 02:17 AM
  2. error invalid conversion from ‘const void*’ to ‘void*’
    By Wahidin Wahid in forum C Programming
    Replies: 3
    Last Post: 03-27-2012, 08:18 PM
  3. difference between void and static void function
    By mahaju in forum C++ Programming
    Replies: 7
    Last Post: 12-27-2011, 03:02 AM
  4. Replies: 12
    Last Post: 03-27-2009, 02:36 PM
  5. Invalid conversion from 'const void*' to 'void*' error
    By prawntoast in forum C Programming
    Replies: 3
    Last Post: 05-01-2005, 10:30 AM

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