0

I got an error when compiling my program:

LNK2001 unresolved external symbol "public: static class Bomb * * Bomb::bombs" (?bombs@Bomb@@2PAPAV1@A)

I know that I have to define static Bomb *bombs[14] in my .cpp, but I don't know how.

My .h file:

class Bomb {
public:
static Bomb *bombs[14];
static int num_bombs;
...

What do I need to add in my .cpp file?

Don't Panic
  • 41,125
  • 10
  • 61
  • 80

2 Answers2

1

The missing line is:

Bomb *Bomb::bombs[14];

You need to qualify it with the class name, since it's part of the declaration. Also, you don't need the static part in the definition.

Blindy
  • 65,249
  • 10
  • 91
  • 131
0

To make your code compile just add Bomb *(Bomb::bombs[size]); to your code (Notice the Bomb:: since bombs is a member of the Bomb class).

However I don't think this is good design and I believe you have a logical error here. When you try to create an instance of 1 Bomb, it will possess an array of pointers to other Bombs, which will each contains arrays of pointers to other Bombs and so on.

I would suggest instead to create a different class, maybe called Map that has one array filled with Bomb instances.

bpgeck
  • 1,592
  • 1
  • 14
  • 32
  • 1
    You're missing entire chunks of knowledge to be making that judgement. There's nothing wrong with an array of pointers to an object. – Blindy Aug 13 '15 at 21:34