Sign in to follow this  

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 this post

Link to post
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 this post

Link to post
Share on other sites
Lith    429
Original post by Lith
Do it like this, not like that.

I knew it...

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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this