Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Is there aA correct way of specializing member functions of template classes? (http://www.velocityreviews.com/forums/t744350-is-there-aa-correct-way-of-specializing-member-functions-of-template-classes.html)

m0shbear 03-01-2011 05:30 AM

Is there aA correct way of specializing member functions of template classes?
 
Suppose I have the following:
foo.h--
template <class T>
class Foo {
T bar(const T&);
};

foo.cpp--
#include "foo.h"
int Foo<int>::bar(const int& x) {
....
return ...;
}

The compile fails with " error: too few template-parameter-lists" (g++
4.5).

Is there a correct way to properly specialize such member functions?
As there is a small, finite set of T to be used, I want to specialize
for all T.

Nobody 03-01-2011 06:47 AM

Re: Is there aA correct way of specializing member functions of template classes?
 
On Mon, 28 Feb 2011 21:30:14 -0800, m0shbear wrote:

> int Foo<int>::bar(const int& x) {
> ...
> return ...;
> }
>
> The compile fails with " error: too few template-parameter-lists" (g++
> 4.5).
>
> Is there a correct way to properly specialize such member functions?


template<>
int Foo<int>::bar(const int& x) {


Paul 03-01-2011 09:48 AM

Re: Is there aA correct way of specializing member functions of template classes?
 

"m0shbear" <andrey.vul@gmail.com> wrote in message
news:a2443ccb-a350-44c2-bbd7-fc9eb41a988f@s18g2000vbe.googlegroups.com...
> Suppose I have the following:
> foo.h--
> template <class T>
> class Foo {
> T bar(const T&);
> };
>
> foo.cpp--
> #include "foo.h"
> int Foo<int>::bar(const int& x) {
> ...
> return ...;
> }
>
> The compile fails with " error: too few template-parameter-lists" (g++
> 4.5).
>
> Is there a correct way to properly specialize such member functions?
> As there is a small, finite set of T to be used, I want to specialize
> for all T.
>


AFAIK you cannot specialise the member function without specialising the
whole class.
..



All times are GMT. The time now is 03:45 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.