Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > error in using template

Reply
Thread Tools

error in using template

 
 
Jayden Shui
Guest
Posts: n/a
 
      02-06-2012
Hi All,

I have a small code to calculate binary operation of two arrays

#pragma once
#include <functional>

template<template<typename T> class Fn, typename T>
struct Apply
{
template<int N>
void To(T* r, T const* left, T const* right) const
{
r[N-1] = Fn<T>()(left[N-1], right[N-1]);
Apply<Fn, T>().To<N-1>(r, left, right);
}

template<>
void To<0>(T* r, T const* left, T const* right) const
{}
};

int main()
{
int a[3], b[3], c[3];
Apply<std:lus, int>().To<3>(a, b, c); // a = b + c;
return 0;
}

When compilation, I get error:

error : no instance of function template "Apply<Fn, T>::To" matches
the specified type.

Please help me find the bug. Thanks a lot!!

Jayden
 
Reply With Quote
 
 
 
 
Chenglong Chen
Guest
Posts: n/a
 
      02-07-2012
On 2月7日, 上午12时16分, Jayden Shui <(E-Mail Removed)> wrote:
> Hi All,
>
> I have a small code to calculate binary operation of two arrays
>
> #pragma once
> #include <functional>
>
> template<template<typename T> class Fn, typename T>
> struct Apply
> {
> template<int N>
> void To(T* r, T const* left, T const* right) const
> {
> r[N-1] = Fn<T>()(left[N-1], right[N-1]);
> Apply<Fn, T>().To<N-1>(r, left, right);
> }
>
> template<>
> void To<0>(T* r, T const* left, T const* right) const
> {}
>
> };
>
> int main()
> {
> int a[3], b[3], c[3];
> Apply<std:lus, int>().To<3>(a, b, c); // a = b + c;
> return 0;
>
> }
>
> When compilation, I get error:
>
> error : no instance of function template "Apply<Fn, T>::To" matches
> the specified type.
>
> Please help me find the bug. Thanks a lot!!
>
> Jayden




hi,



#include <functional>
template<template<typename T> class Fn, typename T , int N>
struct Apply
{
void To(T* r, T const* left, T const* right) const {
r[N-1] = Fn<T>()(left[N-1], right[N-1]);
Apply<Fn, T, N-1>().To(r, left, right);
}
};
template<template<typename T> class Fn, typename T>
struct Apply<Fn,T,0>
{
void To(T* r,T const* left, T const* right) const {}
};

int main()
{
int a[3], b[3], c[3];
Apply<std:lus, int, 3>().To(a, b, c); // a = b + c;
return 0;
}
 
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
How to use the template member function of a template in the memberfunction of another template class? Peng Yu C++ 3 10-26-2008 03:51 PM
template template arguments: expected a class template, got `Component<T1, T2, T3> gary.bernstein@gmail.com C++ 1 06-08-2007 07:10 AM
Compiler error occurred when try to use a flexible template expression in preprocessor definesCompiler error occurred when try to use a flexible template expression in preprocessor defines snnn C++ 6 03-14-2005 04:09 PM
Re: A Newbie Question about template template template tom_usenet C++ 0 07-24-2003 12:06 PM
Re: A Newbie Question about template template template Chris Theis C++ 2 07-24-2003 09:42 AM



Advertisments