Templates are nasty things, and I try to avoid them at all costs.  But to
the best of my understanding, there is no implementation of templates in
.CPP files because the template implementation still requires some blanks to
be filled in when it is used.

For example, a template class "TestClass" would be defined in "TestClass.h":

--- begin: TArray.h ---
template <class T, int i> class TArray {
public:
   T buffer[i];
   T& at(int n);
};

template <class T, int i>
T& TArray<T,i>::at(int n) {
    return buffer[n];
};

--- end: TArray.h ---

(Note that the implmentation of the method get() is present in the .H file)

Now to use this template in MyProg.cpp:

--- begin: myprog.cpp ---
#include <TArray.h>
// declares variable "five_chars" to be a 5 char array using "TestClass".
TArray<char, 5> five_chars;
--- end: myprog.cpp ---

If the implementation of the get() method had been buried in some
"TArray.cpp" file, then it would not have been available when we
instantiated the class in "myprog.cpp", and it -must- be available
because the blanks (represented by "T" and "i") had to be filled in
(with "char" and "5") when we instantiated it.

So ... if your template class implementation is in a separate .cpp
file, move it all to the .h file and see if that helps.

--
-Richard M. Hartman
[EMAIL PROTECTED]

186,000 mi/sec: not just a good idea, it's the LAW!


Anne Srinivas wrote in message <[EMAIL PROTECTED]>...
>
>I need to have a templete class in my project.
>The header file of the class is in a file called a.h
>The implementation of the class is in a file called a.cpp
>
>I have included a.h in my main file starter.cpp
>But it's giving me link error  saying that the function i am using is
>undefined.
>Why is it so.?
>
>Any help will be appreciated
>
>
>--
>Anne Srinivas
>Software Engineer
>InfoTech Enterprises Ltd.
>Plot No 11,Infocity,
>Software Units Layout,
>Madhapur,Hyderabad 33
>
>E-Mail :
>[EMAIL PROTECTED]
>[EMAIL PROTECTED]
>
>Tel (Office) : 3100855
>Tel (Resi)   : 3033761
>
>
>
>





-- 
For information on using the ACCESS Developer Forums, or to unsubscribe, please 
see http://www.access-company.com/developers/forums/

Reply via email to