extern problem

Started by
13 comments, last by DigitalDelusion 19 years ago
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.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
Advertisement
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;   // 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 problem with designing something completely foolproof is tounderestimate the ingenuity of a complete fool. - Douglas AdamsEmail: thefatgecko@yahoo.co.ukhttp://www.geocities.com/thefatgecko
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:
// 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.
Rob Loach [Website] [Projects] [Contact]
Quote:Original post by DigitalDelusion
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 :)
Correction, but ya, you need a definition somewhere in a .cpp file.
Quote:Original post by Roboguy
Quote:Original post by DigitalDelusion
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 :)
Correction, but ya, you need a definition somewhere in a .cpp file.


Geez, I always tend to mixup thoose two :) rating cookie for you sir.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats

This topic is closed to new replies.

Advertisement