pointers

M

Michael Sgier

Hello
my simpengine header file:

class CSimpEngine : public CEngine
{
private:
CCamera *gameCamera;
protected:
CCamera *OnGetCamera() { return gameCamera; }
}

calling in the main loop:
#include "simpengine.h"
CCamera *camera = OnGetCamera();

gives me the error: ` OnGetCamera' undeclared (first use this function)

What is my error. I declare OnGetCamera in the header file. then i include
and call it?
THANKS and regards
Michael
 
A

Axter

Michael said:
Hello
my simpengine header file:

class CSimpEngine : public CEngine
{
private:
CCamera *gameCamera;
protected:
CCamera *OnGetCamera() { return gameCamera; }
}

calling in the main loop:
#include "simpengine.h"
CCamera *camera = OnGetCamera();

gives me the error: ` OnGetCamera' undeclared (first use this function)

What is my error. I declare OnGetCamera in the header file. then i include
and call it?
THANKS and regards
Michael

You need to have an instance of CSimpEngine before calling OnGetCamera,
because OnGetCamera is not a static member.
Even if it was a static member, you would still need to fully qualify
it with the class name.

CCamera *camera = CSimpEngine::OnGetCamera(); //For static member

For a non-static member, you need to first create an instance of
CSimpEngine, and then use that instance to call the method.
CSimpEngine MyCSimpEngine;
CCamera *camera = MyCSimpEngine.OnGetCamera();
 
J

John Harrison

Michael said:
Hello
my simpengine header file:

class CSimpEngine : public CEngine
{
private:
CCamera *gameCamera;
protected:
CCamera *OnGetCamera() { return gameCamera; }
}

calling in the main loop:
#include "simpengine.h"
CCamera *camera = OnGetCamera();

gives me the error: ` OnGetCamera' undeclared (first use this function)

What is my error. I declare OnGetCamera in the header file. then i include
and call it?
THANKS and regards
Michael

To get a camera you need a CSimpEngine. That is what you said in the
header file, maybe you didn't mean to say it but that is what you said.
This has nothing to do with pointers, it's basic object orientated
programming.

One solution might be

CSimpEngine a_simp_engine; // create a simple engine
CCamera* a_simp_engine.OnGetCamera(); // get the camera

another might be

CSimpEngine* a_simp_engine = new CSimpEngine();
CCamera* a_simp_engine->OnGetCamera(); // get the camera

There's a very important difference between the two, which you need to
learn about if you don't know it already. I can't tell which is the
correct solution (if any) from what you have posted so far.

BTW why did you call your method 'OnGetCamera', GetCamera would have
been better, no? OnGetCamera suggests that this method will be called in
response to an event, you often see methods like 'OnMouseMove' or
'OnProgramExit' or whatever, but here you should just call it GetCamera.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top