Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > template definition

Reply
Thread Tools

template definition

 
 
antani
Guest
Posts: n/a
 
      02-20-2007
template <typename T>
class tt
{
vector<T> vect;
inline void add(const T & t);
}

Can I define the member function "inline void add(const T & t)"
outside the class interface in the header file?How?
Thanks in advance.

 
Reply With Quote
 
 
 
 
=?iso-8859-1?q?Erik_Wikstr=F6m?=
Guest
Posts: n/a
 
      02-20-2007
On Feb 20, 12:49 pm, "antani" <(E-Mail Removed)> wrote:
> template <typename T>
> class tt
> {
> vector<T> vect;
> inline void add(const T & t);
>
> }
>
> Can I define the member function "inline void add(const T & t)"
> outside the class interface in the header file?How?


Not sure I understand you correctly, but is this what you want?

template <typename T>
class tt
{
vector<T> vect;
inline void add(const T & t);

};

template<typename T>
void tt::add(const T& t)
{
// do stuff
}

--
Erik Wikström

 
Reply With Quote
 
 
 
 
p.lepin@ctncorp.com
Guest
Posts: n/a
 
      02-20-2007
On Feb 20, 2:11 pm, "Erik Wikström"
<(E-Mail Removed)> wrote:
> On Feb 20, 12:49 pm, "antani" <(E-Mail Removed)>
> wrote:
>
> > template <typename T>
> > class tt
> > {
> > vector<T> vect;
> > inline void add(const T & t);

>
> > }

>
> > Can I define the member function "inline void
> > add(const T & t)" outside the class interface in the
> > header file?How?

>
> template<typename T>
> void tt::add(const T& t)
> {
> // do stuff
> }


Shouldn't this be more like this?

template<typename T>
void tt<T>::add(const T& t)
{
// do stuff
}

--
Pavel Lepin

 
Reply With Quote
 
=?iso-8859-1?q?Erik_Wikstr=F6m?=
Guest
Posts: n/a
 
      02-20-2007
On Feb 20, 2:06 pm, (E-Mail Removed) wrote:
> On Feb 20, 2:11 pm, "Erik Wikström"
>
>
>
> <(E-Mail Removed)> wrote:
> > On Feb 20, 12:49 pm, "antani" <(E-Mail Removed)>
> > wrote:

>
> > > template <typename T>
> > > class tt
> > > {
> > > vector<T> vect;
> > > inline void add(const T & t);

>
> > > }

>
> > > Can I define the member function "inline void
> > > add(const T & t)" outside the class interface in the
> > > header file?How?

>
> > template<typename T>
> > void tt::add(const T& t)
> > {
> > // do stuff
> > }

>
> Shouldn't this be more like this?
>
> template<typename T>
> void tt<T>::add(const T& t)
> {
> // do stuff
>
> }


Oops, sorry, yes that is correct.

--
Erik Wikström

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time template list definition / Run-time variable type definition Pierre Yves C++ 2 01-10-2008 02:52 PM
Template-Meta: Finding out whether a template-definition exists Hendrik Schober C++ 16 09-04-2007 11:48 AM
Template member functions in template class with separate definition =?iso-8859-1?q?Erik_Wikstr=F6m?= C++ 5 12-14-2006 01:04 PM
Out-of-class definition of a non-template member of an explicitly specialized class template? BigMan C++ 3 04-22-2005 06:28 AM
can a class definition inside another class's definition Jianli Shen C++ 1 03-13-2005 06:02 PM



Advertisments