473,386 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

defining class-object declaration in header gives error

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
3 1865
"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
Ami
Thanks a lot Heinz for your help. It works now.
Regards

Dec 22 '05 #3
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Harry Pehkonen | last post by:
I have been defining new class methods when I'm trying to simplify some code. But I'm thinking I should just define functions within that method because they aren't useful from the outside anyway....
7
by: Senthilraja | last post by:
I have the following program using templates. Someone please let me know the syntax to be used for defining the member functions push, pop etc. as non-inline functions. #include <iostream>...
8
by: johny smith | last post by:
If I have a simple class with say a couple of integers only is there any need for me to provide a destructor? thanks!
10
by: Joe Laughlin | last post by:
I'm sure there's a fairly easy answer for this... but how can I define a new type with range checking? Example: I want to define a new type that's like a double, except that you can only give...
5
by: Xiangliang Meng | last post by:
Hi, all. What are the benefit and the drawback of defining a class embedded inside another class? For example: class List { public:
5
by: Dale | last post by:
Is it possible to declare a method of an interface as static? For instance, can I create an interface that defines a static method and 2 instance methods?
2
by: lcaamano | last post by:
We have a tracing decorator that automatically logs enter/exits to/from functions and methods and it also figures out by itself the function call arguments values and the class or module the...
9
by: Nick Maclaren | last post by:
I am defining a class, and I need to refer to that class when setting up its static data - don't ask - like this: Class weeble : wumpus = brinjal(weeble) Does anyone know how I can achieve...
2
by: python101 | last post by:
class Dialog: def Dialog(self): self._dial = 'exit' def change(self) index = self.index('x') self._dial='e' def __str__(self):
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.