This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Template problems with link
- From: Saravanan <psaravanan at 7hillsys dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 31 Jan 2002 0:22:21 GMT
- Subject: Template problems with link
- Organization: Intellisys Technology LLC
- Reply-to: Saravanan <psaravanan at 7hillsys dot com>
Hi all,
I have a template declaration as follows in three different files
///////////////////Template.h file///////////////////////////////
#ifndef _TEMPLATE_
#define _TEMPLATE_
template<class Y>
class MyTemplate
{
Y m_Member;
public:
Y ob();
};
#endif
////////////////////Template.cpp file////////////////////////
#include "Template.h"
template <class Y>
Y MyTemplate<Y>::ob()
{
return m_Member;
}
template class MyTemplate<int>; ----> Line that gives error
/////////////////////////Main file//////////////////////////////
#include "Template.h"
main()
{
MyTemplate<int> ob1;
ob1.ob();
}
when I compile this, I am able to link properly. But if I remove the
line that gives error, then I get a link problem. I understand that this
is because of not manually instatiating the template. How do I do
automatic instantiation with g++. I use version 2.96. It is not feasible
for my project to do manual instantiation as done above because there are
too many templates. Previously we had not seperated the implem and
defenition of the templates. But now that we have, we face link errors.
Someone help!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
Regards
Saravanan Palanichami
---------------------------------------------------------
This message sent using EMUmail -- http://www.emumail.com
---------------------------------------------------------
Jumping through hoops to get E-mail on the road?
You've got two choices: Join the circus, or use MollyMail.
Molly Mail -- http://www.mollymail.com