Thread: Void pointer. So, is this an actual object?

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    125

    Void pointer. So, is this an actual object?

    I have a bit of a problem here. I have made a function that has a void pointer as an argument, so this could point to any adress in memory and any data type too, but I have to make sure the pointer points to a valid instance of any class that is derived from an abstract base class. Is this even possible?
    Typing stuff in Code::Blocks 8.02, compiling stuff with MinGW 3.4.5.

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    >I have to make sure the pointer points to a valid instance of any class that is derived from an abstract base class.

    Then you shouldn't be using a void pointer. Use a pointer to the base class.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    125
    I'd do that, but I want to keep the function as open as possible. Well, if there's no other solution that's what I'll do.
    Thanks, and congrats on your 1000th post.
    Typing stuff in Code::Blocks 8.02, compiling stuff with MinGW 3.4.5.

  4. #4
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    You can use templates to accomplish the same thing.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    125
    Hmm... I don't quite know how templates work, but I'll look it up. (I recall there's a tutorial on that in the tutorials section of this board's main site)
    Anyway, right now I'm going to sleep. g'night!
    Typing stuff in Code::Blocks 8.02, compiling stuff with MinGW 3.4.5.

  6. #6
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    As SilentStrike has stated use templates; then if you want to ensure that something is done when you use the function with a specific type, create a specialisation.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  2. How to better manage large .cpp files
    By 39ster in forum C++ Programming
    Replies: 6
    Last Post: 08-25-2008, 08:24 AM
  3. Pls repair my basketball program
    By death_messiah12 in forum C++ Programming
    Replies: 10
    Last Post: 12-11-2006, 05:15 AM
  4. need help with handelling multiple source files
    By DarkMortar in forum C++ Programming
    Replies: 38
    Last Post: 05-26-2006, 10:46 PM
  5. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM