Pointer without a type

This is a discussion on Pointer without a type within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm beginning my first game and was wondering how to implement seperate loops for in game, main menu etc. ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Location
    England
    Posts
    121

    Pointer without a type

    Hi, I'm beginning my first game and was wondering how to implement seperate loops for in game, main menu etc. An idea I was trying to use is to have a base class 'CLoop' and then derive different classes for each type of loop (CGame, CMenu, etc.) In my main function I would make calls to the functions of the appropriate loop. I was hoping that something like this would work:

    CLoop* currentloop = NULL;
    CGame game;
    CMenu menu;
    ...
    currentloop = &menu; //makes 'menu' the active loop
    ...
    currentloop->Draw(); // calls the menu's draw function

    The problem is the call to Draw(); executes CLoop:raw(), despite the pointer pointing to an instance of CMenu, I assume because of the pointer being declared as type CLoop. So, is there any way I can declare a pointer independent of type, and have it point to any class? Hope this post makes sense.

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    148
    Is the methode Draw declarred virtual (keyword) in the base class? I think no.

    Edit: Oh,every class with a virtual methode should have a virtual destructor.
    Last edited by Wledge; 06-08-2003 at 08:37 AM.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Location
    England
    Posts
    121
    That's it , thanks for the help, and for the quick reply.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strings Vs. Char pointers
    By aijazbaig1 in forum C Programming
    Replies: 49
    Last Post: 02-13-2008, 08:51 AM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. Compiler "Warnings"
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 04-24-2005, 01:09 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  5. Another Linked List plee
    By Dragoncaster131 in forum C Programming
    Replies: 3
    Last Post: 05-15-2004, 05:40 PM

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