In my response yesterday I though I explained it. I'll try again. A template class not like a real class, is basically a fancy elaboration on the macro preprocessor (#define, etc).
When you declare the template class, you set aside some pseudo-parameters to be filled in when you instantiate the class. (In this case, "Type"). The template class does not get compiled directly. Instead at the time you declare an instance of this class the code is generated with the pseudo-parameters replaced with whatever you specified in the instantiation (in this case, "Type" would be replaced by "int"). Now ... this can only be done w/ the parts of the template that the compiler can see at the time. When you instantiated "a<int> a1;" the compiler could see "Starter.cpp" and "Header.h". The stuff in "Impl.cpp" was not available to it, so your method implementation never had any code generated for it using "int" in place of "Type". If you get rid of Impl.cpp and place it's entire contents in Header.h, then all parts of the template will be visible when an instantiation is declared. -- -Richard M. Hartman [EMAIL PROTECTED] 186,000 mi/sec: not just a good idea, it's the LAW! Fergal Moran wrote in message <[EMAIL PROTECTED]>... > >Anne > >I don't know the exact cause of your problem - but can suggest a solution as >I have had this problem before. Put the implementation of class a into the >header file and don't bother with the .cpp file and it will link. If anyone >can suggest a cause/proper solution then I would love to hear it. > >Regards, > >Fergal Moran >-- >WASP Technologies >http://www.wasptech.com >Wireless Application Solutions Provider > >> -----Original Message----- >> From: Anne Srinivas [mailto:[EMAIL PROTECTED] >> Sent: 03 August 2000 07:59 >> To: Palm Developer Forum >> Subject: PROBLEMS USING TEMPLATE CLASSES >> >> >> Hai, >> I am trying to use template classes in my application. >> I have 3 files. >> 1. Header.h -- This is header file for class definition >> 2. Impl.cpp -- This is implementation file for class in >> Header.h >> 3. Starter.cpp -- This is my main file >> >> The files are as follows : >> >> Header.h >> template <class Type> >> class a >> { >> public: >> int b; >> void add(int c,int d); >> }; >> >> Impl.cpp >> # include "Header.h" >> template <class Stype> void a<Stype> ::add(int d,int l) >> { >> b=(d+l); >> } >> >> Starter.cpp >> // All includes.... >> #include "Header.h" >> // All other functions.... >> // ...... >> case frmOpenEvent: >> { >> // All necessary code.... >> a<int> a1; >> a1.add(12,13); >> int k=a1.b; >> // All necessary code >> } >> >> Problem is that when i complie this code it's compling with out a >> error. >> But when i try to link it its giving me a link error saying that >> a<int>::add(int,int) referenced from mainformhandleevent is undefined. >> >> What is the problem? >> >> Thanks in advance >> >> Regards >> >> -- >> Anne Srinivas >> Software Engineer >> InfoTech Enterprises Ltd. >> Plot No 11,Infocity, >> Software Units Layout, >> Madhapur,Hyderabad 33 >> >> E-Mail : >> [EMAIL PROTECTED] >> [EMAIL PROTECTED] >> >> Tel (Resi) : 3033761 >> >> >> >> -- >> For information on using the Palm Developer Forums, or to >> unsubscribe, please see http://www.palmos.com/dev/tech/support/forums/ >> > > -- For information on using the ACCESS Developer Forums, or to unsubscribe, please see http://www.access-company.com/developers/forums/
