Jump to content
  • Advertisement
Sign in to follow this  
Lith

Strange Pointers

This topic is 2809 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
Quote:

BobPlayer MainPlayer();

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

Share this post


Link to post
Share on other sites
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
Quote:
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!