W
wakun
Hi there,
I have been using C for years. For some project I've done times ago,
I always need to share variable between modules. The structure of my
project is illustrated as follow
/* global.h */
#ifndef _GLOBAL_H_
#define _GLOBAL_H_
#include "DS.h"
extern int data;
extern DS stru; /* DS is a struct definied in DS.h */
#endif
/* global.c */
#include "DS.h"
#include "global.h"
int data;
DS stru;
#endif
So, I only need to include global.h when and where I need to access
data and stru. Moreover, though the whole session, only one instance
of data and stru is kept.
Now, I have changed to use C++ instead and class is involved.
Similarly, I organize my project as follow
// global.hpp
#ifndef _GLOBAL_H_
#define _GLOBAL_H_
#include "DC.hpp"
extern int data;
extern DC dc(2); /* DC is a class definied in DC.hpp */
#endif
// global.cpp
#include "DC.hpp"
#include "global.hpp"
int data;
DC dc(2);
#endif
Note that dc take an integer as parameter.
I am intending to keep one instance of DC(i.e. dc) in the whole
project. However, I found it fail to compile the following code
// main.hpp
#include "global.hpp"
int main(void)
{
dc.show();
return 0;
}
Any idea?
I have been using C for years. For some project I've done times ago,
I always need to share variable between modules. The structure of my
project is illustrated as follow
/* global.h */
#ifndef _GLOBAL_H_
#define _GLOBAL_H_
#include "DS.h"
extern int data;
extern DS stru; /* DS is a struct definied in DS.h */
#endif
/* global.c */
#include "DS.h"
#include "global.h"
int data;
DS stru;
#endif
So, I only need to include global.h when and where I need to access
data and stru. Moreover, though the whole session, only one instance
of data and stru is kept.
Now, I have changed to use C++ instead and class is involved.
Similarly, I organize my project as follow
// global.hpp
#ifndef _GLOBAL_H_
#define _GLOBAL_H_
#include "DC.hpp"
extern int data;
extern DC dc(2); /* DC is a class definied in DC.hpp */
#endif
// global.cpp
#include "DC.hpp"
#include "global.hpp"
int data;
DC dc(2);
#endif
Note that dc take an integer as parameter.
I am intending to keep one instance of DC(i.e. dc) in the whole
project. However, I found it fail to compile the following code
// main.hpp
#include "global.hpp"
int main(void)
{
dc.show();
return 0;
}
Any idea?