-3

I,m this class :

class Foo {
private:
    Objet grid;
    static Player *players[2];
public:
    Foo(int len, string ps1, string ps2);
};

When i do this :

Foo::Foo(int len, string ps1, string ps2){
    grid.setLen(len);
    players[0] = new Ange(ps1, grid.getLen()/2, grid.getLen/2);
    players[1] = new Demon(ps2);
}

Player is a class abstract and Ange et Demon herited to class Player

I'm this error to xCodes when i compile

Undefined symbols for architecture x86_64: "Partie::joueurs", referenced from: Partie::Partie(int, std::__1::basic_string, std::__1::allocator >, std::__1::basic_string, std::__1::allocator >) in Partie.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

help me please !!!

Excuse my english i'm french

Darkness007
  • 93
  • 2
  • 12

1 Answers1

1

The static member variable is only declared, you need to define it as well.

It's simplest done by adding, in a source file somewhere:

Player *Foo::players[2];

Though you should not initialize static member variables in the constructor, what do you think would happen if you create Two (or more) Foo objects?

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621