The well known method for this is to declare int globalVar = 0 and then -where to use it- extern int globalVar; but that didn’t work with me for objects from user defined class!
This is an example of what I did:
file1.cpp:
#include "file2.h"
class list { ....};
list * x ;
//do something with x`
file2.cpp:
class list;
extern list * x;
//do something with x
and this is the error I get:
error C2027: use of undefined type 'list'
if I remove class list
error C2143: syntax error : missing ';' before '*' // in `extern list *x;`
error C4430: missing type specifier - int assumed. Note: C++ does not support
default-int
thanks for answers , now it’s like this :
#ifndef _ERRLIST_H_
#define _ERRLIST_H_
#include <queue>
#include <string>
struct errorStruct{
int errLineNum;
int errColNum ;
char * errMessage;
};
queue <errorStruct> errQueue; //error points here
class ErrList
{
public:
void pushError(int line,int col,char * message);
void popError();
void printErrors();
int getSize();
};
#endif
but I get this error :
error C2143: syntax error : missing ';' before '<'
It’s “std::queue<errorStruct>”, not “queue<errorStruct>”.