# Strange Pointers

## Recommended Posts

Lith    429
First of all, im sorry.

This is a simple question and the answer is properly going be something like:
"Do it like this, not like that". I have tried google and to honest, that confused me even more.

Now, i dont think im a newb with pointers, i have used them successfully before and i think they are VERY useful. Here is the code that "Isnt Working".
BobPlayer MainPlayer();int main(int argc, char **argv){	PointerToMainPlayer = &MainPlayer;}

Now this obviously isnt my whole main, i have just given you the error line.

I have declared "PointerToMainPlayer" in a file called "Globals.h" and i included it in main.cpp

Here is a slice of Globals.h
#include "PlayerClass.h"extern BobPlayer* PointerToMainPlayer;

And here is a slice of Globals.cpp
#include "Globals.h"#include "PlayerClass.h"BobPlayer* PointerToMainPlayer = NULL;

What i THINK im doing is declaring a pointer to my class, making another instance of it and making the pointer point to the new instance.

I get this error from VC++ 2008:
error C2440: '=' : cannot convert from 'BobPlayer (__cdecl *)(void)' to 'BobPlayer *

I dont have much of an idea as to what this error means. All i know is that mabye i have made 2 different types of the BobPlayer class?

Any help would be appreciated :)

##### Share on other sites
KulSeran    3267
Quote:
 BobPlayer MainPlayer();

The compiler thinks this is a function definition.
You need to just write
BobPlayer MainPlayer;

##### Share on other sites
nobodynews    3126
You weren't making an object named MainPlayer you were making a function declaration named MainPlayer that returns a BobPlayer. When declaring a variable without any parameters in its constructor you define it like this:

BobPLayer MainPlayer;

##### Share on other sites
Lith    429
Quote:
 Original post by LithDo it like this, not like that.

I knew it...

But thanks for the help, it's working now.

## Create an account

Register a new account