PDA

View Full Version : using class objects globally??????



pratik
9th July 2007, 09:32
hello all

i have created three classes in qt 4.2...

say

a.h
b.h
c.h

and corres. source file

a.cpp
b.cpp
c.cpp

now i want to use the object of class which is declared in a.h and defined in a.cpp in b.cpp and c.cpp.............


the problem is if i declare it in a.h after the class declaration and then include a.h in both b.cpp and c.cpp then its giving the linker error.......

the error is multiple defination of class object................

please help as this the normal way of doing it in OOPS........

i have wraped all the .h files in the macro #ifndef #define #endif........

thanking all in anticipation

jpn
9th July 2007, 09:54
Maybe class A could provide static methods? If not, there's always Singleton pattern (http://en.wikipedia.org/wiki/Singleton_pattern).. :)

rajesh
9th July 2007, 13:51
dont do multiple defination of class object in all cpp file.
do you want to acess same object in all cpp file then write singleton class.
you declare singlton class in a.h and create any number of object with or without same object name in different cpp file. it will treated as same object.