simple solution: create InitLog and InitInput functions that simply creates the objects and assigns the pointers into the correct units then in main simply go:
InitLog();
InitInput();
simple works get the job done.
extern problem
If you just what a "quick hack" so that your current code will run, get rid off
CInput* input = new CInput... in windows.cpp
and alter the file to:
CInput* input = new CInput... in windows.cpp
and alter the file to:
CInput* input; // This is where CInput* input is actually stored // and is why your linker was previously grumblingvoid InitInput() // or where ever you initialise CInput{ ... input = new CInput ...}
The Gecko is correct. You need to have all declarations in your *.h and all your definitions in your *.cpp. Another thing you could implement to make your life easier are namespaces:
This will help you handle the global variables in different modules. You just have to use InputModule::Initialize() to initialize the input module.
// input.h#ifndef _INPUT_H_#define _INPUT_H_namespace InputModule { class CInput { void SomeFunction(); }; extern CInput *input; // declaration void Initialize(); // declaration}#endif// input.cpp#include "input.h"namespace InputModule { CInput *input; // definition void Initialize() { input = new CInpput(); } void CInput::SomeFunction(){ // definition // code }}
This will help you handle the global variables in different modules. You just have to use InputModule::Initialize() to initialize the input module.
Quote:Original post by DigitalDelusionCorrection, but ya, you need a definition somewhere in a .cpp file.
I see a definition declaration but no declaration definition. Where exactly did you put the declaration definition of that pointer? it has to reside in some sourcefile somehwere you know :)
Quote:Original post by RoboguyQuote:Original post by DigitalDelusionCorrection, but ya, you need a definition somewhere in a .cpp file.
I see a definition declaration but no declaration definition. Where exactly did you put the declaration definition of that pointer? it has to reside in some sourcefile somehwere you know :)
Geez, I always tend to mixup thoose two :) rating cookie for you sir.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement