Thread: allegro timer in a class

  1. #1
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176

    Unhappy allegro timer in a class

    okay.. so i'm sort of making this game (not really.. it's mostly just to get the hang of allegro). i've got a class 'player' (first class i've done in C++, though i've used them in java before, so i get the idea). i need to use a timer for some stuff, but i'm having trouble with it.. here's some code.

    in player.h:
    Code:
    #ifndef PLAYER_H
    #define PLAYER_H
    
    class player
    {
    public:
       //public stuff
    private:
       //bunch of private stuff
    
       int count;		//for use with timer
    
       //private functions
       void countUp();   //to increment count
       void setup();   //to set stuff up
    };
    
    #endif
    okay.. so far so good (i think/hope).

    so here's some of the player.cpp (namely setup() and countUp())

    Code:
    void player::setup()
    {
    	allegro_init();
    	install_timer();
    	install_int_ex(countUp, BPS_TO_TIMER(100));
    }
    
    void player::countUp()
    {
    	++count;
    }
    i got rid of the stuff i didn't think was relavent.

    so here's the problem.. when i try to compile it, i get this:

    Code:
    C:\Development\C\game\player.cpp(36) : error C2664: 'install_int_ex' : cannot convert parameter 1 from 'void (void)' to 'void (__cdecl *)(void)'
            None of the functions with this name in scope match the target type
    any ideas? i've tried putting player::countUp in the install_int_ex, changing variables/functions to public, among other things, but nothing seems to work.

    help is appreciated.

    btw, i've gotten a timer like this to work before.. just not in a class i made myself.

  2. #2
    Aryoc
    Guest
    I think the problem is that it doesn't "see" countUp() because it's a member function of the class... It would probably work if you make countUp a normal function outside of the class, but that's probably not what you want. There's probably a way to get that to work with the member function, but I can't remember what it might be

  3. #3
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    thanks for the reply. i was thinking this is probably the case aswell (it not "seeing" countUp). there must be someone out there who knows how to do this... anyway? i've searched the forums and the 'net, but no luck...

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Just an irrelevant thought, but usually people use 'protected' instead of 'private' (at least according to my book or instructor or something/somebody respectable ), since protected members can be accessed by derived classes and privates can't... and supposedly, people *don't* run into problems with protected that they run into with public. Or something like that anyways, I forget the whole explanation
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #5
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    thanks for the tip, hunter. in the book i was learning from (c++: how to program, i think) it was using private. i haven't gotten into classes in class yet (next simester), so i don't know what we'll use there. i'll keep it in mind for the future though. thanks.

    P.S. not that that wasn't a useful fact (it was), but does anyone have an answer for my original question?

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    lol oh well, don't worry about it until you get into inheritance - private is fine.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  7. #7
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    This came from a poster named spellcaster at allegro.cc He is very proficient when it comes to programming so I would take his word for it. Well, here are his thoughts on how classes should be laid out---

    Code:
    class Foo {
    public:
         // All the public methods go here
         // No variables in this section
    
    protected:
         // All helper methods go here, so subclasses
         // can use them as well.
         // You might want to put a few vars here.
         // Only a few.
    
    private:
         // all other variables go here
         // Same for methods / constructors which
         // should not be callable from the outside
         // (say to forbid the default constructor)
    };

  8. #8
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    well, i'm working around it for now. i just created a timer in the main program and call a function in the player class each time the timer ticks (or whatever it does).

    but hey, don't let this stop you from giving me some hints if you have any

    btw, thanks techwin for the info. maybe i'll take a look at the allegro.cc boards and see if there's any answers to my problem...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 3
    Last Post: 10-31-2005, 12:05 PM
  3. timer class
    By [EMOBA] in forum C++ Programming
    Replies: 2
    Last Post: 09-11-2002, 10:30 AM
  4. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM