May I use a global data in a class?

S

shuisheng

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
 
D

Davlet Panech

shuisheng said:
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?
 
S

shuisheng

Davlet Panech 写é“:
#include "CA.h"


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


What errors are you getting?

I found the reason. I cross-referenced the two head files. Thanks for
your reply.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,220
Latest member
MathewSant

Latest Threads

Top