By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

May I use a global data in a class?

P: n/a
Dear All,

Would you please help me to look at this case?

// "CA.h"
class CA
{
};

// "CA.cpp"
CA a;

// "CB.h"
extern CA a;
class CB
{
public:
// fun() use global data a.
void fun()
{
....
a.fun();
....
}
};

I think this is ok, but the compiler gives me lots of error.

Anybody can help me to correct it?
Thanks,

Shuisheng

Sep 19 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
shuisheng wrote:
Dear All,

Would you please help me to look at this case?

// "CA.h"
class CA
{
};

// "CA.cpp"
CA a;

// "CB.h"
#include "CA.h"
extern CA a;
class CB
{
public:
// fun() use global data a.
void fun()
{
....
a.fun();
There's no member "fun" in class "CA".
....
}
};

I think this is ok, but the compiler gives me lots of error.
What errors are you getting?

Sep 19 '06 #2

P: n/a

Davlet Panech 写道:
shuisheng wrote:
Dear All,

Would you please help me to look at this case?

// "CA.h"
class CA
{
};

// "CA.cpp"
CA a;

// "CB.h"

#include "CA.h"
extern CA a;
class CB
{
public:
// fun() use global data a.
void fun()
{
....
a.fun();

There's no member "fun" in class "CA".
....
}
};

I think this is ok, but the compiler gives me lots of error.

What errors are you getting?
I found the reason. I cross-referenced the two head files. Thanks for
your reply.

Sep 19 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.