pb with template function in non template class 
Author Message
 pb with template function in non template class

Hi,
I'm experiencing trouble with this simple code, is there a pb with
template functions in non template class? :
CMaths.cpp
error C2893: Failed to specialize function template 'T __thiscall
CMaths::ValAbs(T &)'With the following template arguments:'float'

CMaths.h :
class CMaths
{
    public:
        template<class T> T ValAbs(T& x);

Quote:
};

CMaths.cpp :
template <class T> T ValAbs(T& x))
{
  if (x>=0)
    return x;
  else
    return -x;

Quote:
}

void OtherFunc()
{
 CMaths MyMaths;
 float x = -2.0f;
 float y = MyMaths.ValAbs(x);

Quote:
}

      Thanks!

        Fabrice

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sun, 29 Dec 2002 03:00:00 GMT  
 pb with template function in non template class

Quote:

> Hi,
> I'm experiencing trouble with this simple code, is there a pb with
> template functions in non template class? :
> CMaths.cpp
> error C2893: Failed to specialize function template 'T __thiscall
> CMaths::ValAbs(T &)'With the following template arguments:'float'

> CMaths.h :
> class CMaths
> {
>     public:
> template<class T> T ValAbs(T& x);
> };

> CMaths.cpp :
> template <class T> T ValAbs(T& x))

template<class T> T CMaths::ValAbs(T& x)
                    ^^^^^^^^

Quote:
> {
>   if (x>=0)
>     return x;
>   else
>     return -x;
> }

> void OtherFunc()
> {
>  CMaths MyMaths;
>  float x = -2.0f;
>  float y = MyMaths.ValAbs(x);
> }

Victor
--
Please remove capital A's from my address when replying by mail


Sun, 29 Dec 2002 03:00:00 GMT  
 pb with template function in non template class

We've already discussed this today:

BUG with templates(?)

Sergei

Quote:

> Hi,
> I'm experiencing trouble with this simple code, is there a pb with
> template functions in non template class? :
> CMaths.cpp
> error C2893: Failed to specialize function template 'T __thiscall
> CMaths::ValAbs(T &)'With the following template arguments:'float'

> CMaths.h :
> class CMaths
> {
>     public:
> template<class T> T ValAbs(T& x);
> };

> CMaths.cpp :
> template <class T> T ValAbs(T& x))
> {
>   if (x>=0)
>     return x;
>   else
>     return -x;
> }

> void OtherFunc()
> {
>  CMaths MyMaths;
>  float x = -2.0f;
>  float y = MyMaths.ValAbs(x);
> }

>       Thanks!

>         Fabrice

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Sun, 29 Dec 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. template member function - non template class - VC5 - error

2. Template function in non-template class

3. Template function in a non-template class

4. Template function in non-template class

5. Syntax for declaring a template class as a friend of a non-template class

6. template functions in template classes declared outside the class definition

7. C++ compiler bug: template and non template function overload resolution

8. template class with a template member function

9. Template function within Template Class

10. Template member functions of template classes

11. calling template member function in template class

12. Function template as member in a class template

 

 
Powered by phpBB® Forum Software