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

defining class-object declaration in header gives error

P: n/a
Ami
Hi All,
I have a class and i want to share the instance of it, to many
different units. To do this, I have declared the class type object in
common header file, which is included in required units.

e.g. Class_AB *objabc;

When i try to compile program, it gives me 100's of error message. am I
doing wrong? How to share otherwise the object instance in different
program units.

I am using VC++6.0 as programming IDE.

Thanks in advance for suggestions.

Dec 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Ami" <ve*********@yahoo.com> schrieb im Newsbeitrag
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi All,
I have a class and i want to share the instance of it, to many
different units. To do this, I have declared the class type object in
common header file, which is included in required units.

e.g. Class_AB *objabc;

When i try to compile program, it gives me 100's of error message. am I
doing wrong? How to share otherwise the object instance in different
program units.


Don't define variables in header files. Define them in only one CPP file and
write an extern declaration in the header. Share only the declaration:

// Header.h
extern Class_AB* objabc;
// CPP file
#include "Header.h"
....
Class_AB* objabc;

HTH
Heinz
Dec 22 '05 #2

P: n/a
Ami
Thanks a lot Heinz for your help. It works now.
Regards

Dec 22 '05 #3

P: n/a
Ami a écrit :
Hi All,
I have a class and i want to share the instance of it, to many
different units. To do this, I have declared the class type object in
common header file, which is included in required units.

e.g. Class_AB *objabc;

When i try to compile program, it gives me 100's of error message. am I
doing wrong? How to share otherwise the object instance in different
program units.

I am using VC++6.0 as programming IDE.

Thanks in advance for suggestions.


Define the class type object in source file and in the associated header
in extern like this:

in test.c:
static Class_AB* objabc[ = ...];

in test.h:
extern Class_AB* objabc;

This will work ...

Marco
Dec 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.