help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Defining template class methods outside class definition


From: Paul Pluzhnikov
Subject: Re: Defining template class methods outside class definition
Date: 11 Aug 2004 09:06:55 -0700
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Artificial Intelligence)

Martin Magnusson <martin@-xx-blecket-xx-.org> writes:

> I have a templated class, and I want to keep the implementation in a
> separate file, and not in the header file. 

This will not work with 'g++' and most other C++ compilers.

> Shouldn't the code below work?

No, because it has a syntax error.

Correct code is:

  template<int N> 
  vertex<N>::vertex() { [...] }

However, after you compile the fixed test.cpp, you'll end up with
an empty object file: 'g++' does not instantiate templates until
they are used (which is why they should be in the header file).

Cheers,
-- 
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]