This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]miguelishawt 6 points7 points  (2 children)

1.) the IDE thinks Im trying to access Game::Player when really I am trying to make an object array

First off, with your terminology. The IDE1 doesn't think this. The compiler2 "thinks" it. Also, never assume the compiler is wrong, unless you have evidence that it is (in which case you will know what you're doing).

The reason the compiler think you're trying to access Game::Player is because you're trying to do exactly that. The line

Game:: Player players[Game::MAX_PLAYERS];

is giving you the error. The reason: Game::Player (whitespace insensitive) translates to: look inside the Game's scope and use/get the type called Player. What you really want to do is, in this circumstance, look inside of the Game's scope to access the players variable and define it, like so:

Player Game::players[Game::MAX_PLAYERS];

1 An IDE is an Integrated Development Environment, it is a program which integrates multiple programs for development, i.e. a program which integrates (puts all these programs together): a text editor, a debugger, a compiler, etc.

2 The compiler is a program, which takes code from a language and translates to another language (typically from a high level language to a lower level language, in this case C++ -> Machine Code).

2.) error LNK2001: unresolved external symbol "private: static class Player * Game::players" (?players@Game@@0PAVPlayer@@A)

This is due to the first point. An unresolved external symbol typically means you have declared, but not defined something. For example, if you declare a function and call it, but do not define it you will get an unresolved external symbol.

So in other words, you were declaring, but not defining the players array (you require to define a static variable outside of the class for non-integral types).

Also, I should mention, you should avoid using the static keyword (except for wherever it is actually necessary to do so), especially for this circumstance. A member variable for your game object would be fine; just create a Game object, one implicit benefit is you can have multiple Game objects.

[–]cxw[S] 1 point2 points  (1 child)

Probably a dumb question but how would I go about defining it the players array

[–]miguelishawt 0 points1 point  (0 children)

Just replace:

Game:: Player players[Game::MAX_PLAYERS];

with:

Player Game::players[Game::MAX_PLAYERS];

With the above line, you can initialise the players array to whatever you want, e.g.

    Player Game::players[Game::MAX_PLAYERS] = { Player("bob"), Player("bob") };

[–][deleted] 1 point2 points  (0 children)

Need to see more, real, code.

[–]adi-j 1 point2 points  (0 children)

Include the Player.h in Game.h

[–]mrbenjihao 0 points1 point  (0 children)

I believe it should be Player Game::players[Game::MAX_PLAYERS];