GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


pointers++ for locke++ by godecho
1
 
#include <cstdio>

class Foo
{
    public:
        
        Foo(){}
        ~Foo(){}

        int number;
};

class Group
{
    public:

        Group()    {    usedup = 0;    }
        ~Group(){}

        Foo* pointers[2];

        void addFoos(Foo *addme);
        void update();

    private:
        
        int usedup;
};

void Group::addFoos(Foo *addme)
{
    if(usedup == 2)
        return;

    pointers[usedup] = addme;
    usedup++;
}

void Group::update()
{
    pointers[0]->number += 10;
    pointers[1]->number += 10;
}

void main()
{
    Foo myfoo1;
    Foo myfoo2;
    Group mygroup;
    
    myfoo1.number = 1;
    myfoo2.number = 2;

    mygroup.addFoos(&myfoo1);
    mygroup.addFoos(&myfoo2);

    mygroup.update();

    printf("myfoo1 is: %i, myfoo2 is: %i\n", myfoo1.number, myfoo2.number);
}