C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

class templates & constructor defn outside the class

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
gopal
Guest





PostPosted: Sat Jun 17, 2006 9:10 am    Post subject: class templates & constructor defn outside the class Reply with quote



I have the following class template declaration

//class template declaration
template <class T> class A {
public:
T t1;
A(T);
};

I would like to define the class A constrcutor outside. Any help
please?

Regards
JK
Back to top
Ian Collins
Guest





PostPosted: Sat Jun 17, 2006 9:10 am    Post subject: Re: class templates & constructor defn outside the class Reply with quote



gopal wrote:
Quote:
I have the following class template declaration

//class template declaration
template <class T> class A {
public:
T t1;
A(T);
};

I would like to define the class A constrcutor outside. Any help
please?

Well that all depends on how your compiler looks for class template

member definitions. If it supports 'export' or uses other means to
locate them, you can put the definition in an appropriate source file.
Otherwise you have to include the definition in the header.

template <class T>
A<T>::A( T )
{
...
}

--
Ian Collins.
Back to top
gopal
Guest





PostPosted: Sat Jun 17, 2006 9:10 am    Post subject: Re: class templates & constructor defn outside the class Reply with quote



Hi tried the above code and i got the following error

1. __ctor' : is not a member of 'A<T>
2. A<T>' : template-class-id redefined as a global function
3. initializing' : cannot convert from 'const int' to 'class
A<int>



Ian Collins wrote:
Quote:
gopal wrote:
I have the following class template declaration

//class template declaration
template <class T> class A {
public:
T t1;
A(T);
};

I would like to define the class A constrcutor outside. Any help
please?

Well that all depends on how your compiler looks for class template
member definitions. If it supports 'export' or uses other means to
locate them, you can put the definition in an appropriate source file.
Otherwise you have to include the definition in the header.

template <class T
A<T>::A( T )
{
..
}

--
Ian Collins.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.