B
Bill
Hi,
I have a quetion how to specialization a non-type templat function, I
use VC++ 2005.
My code is:
#include "stdafx.h"
enum VariableType
{
enumASCII = 1,
enumDOUBLE = 2,
enumDURATION = 3,
enumINTEGER = 4
};
template< VariableType >
struct HrtTypes{
};
template< size_t _size >
struct INTEGERS
{
typedef signed char value_type;
typedef signed char* pointer;
typedef HrtTypes<enumINTEGER> TypeTrait;
enum { size = _size };
};
template<typename T>
bool foo(T*, typename T::TypeTrait*);
//specializaton for INTEGERS<1>,<2>, ...<n>
template<typename T>
bool foo(T*, HrtTypes<enumINTEGER>*)
{
return true;
}
int main()
{
INTEGERS<1>* p1;
foo(p1, INTEGERS<1>::TypeTrait*(0));
size_t n = 4;
INTEGERS<4> p2;
foo(p2, INTEGERS<4>::TypeTrait*(0));
}
I hope all INTEGERS<1>...type can use the specilization for template
function foo(....). I think the compiler could get that
HrtTypes<enumINTEGER> is same with INTEGERS<1>::TypeTrait, so foo(p1,
INTEGERS<1>::TypeTrait*(0)) and foo(p2, INTEGERS<4>::TypeTrait*(0));
can call the same function above.
but it seems these not works.
who can give me more comments
Thanks very well.
I have a quetion how to specialization a non-type templat function, I
use VC++ 2005.
My code is:
#include "stdafx.h"
enum VariableType
{
enumASCII = 1,
enumDOUBLE = 2,
enumDURATION = 3,
enumINTEGER = 4
};
template< VariableType >
struct HrtTypes{
};
template< size_t _size >
struct INTEGERS
{
typedef signed char value_type;
typedef signed char* pointer;
typedef HrtTypes<enumINTEGER> TypeTrait;
enum { size = _size };
};
template<typename T>
bool foo(T*, typename T::TypeTrait*);
//specializaton for INTEGERS<1>,<2>, ...<n>
template<typename T>
bool foo(T*, HrtTypes<enumINTEGER>*)
{
return true;
}
int main()
{
INTEGERS<1>* p1;
foo(p1, INTEGERS<1>::TypeTrait*(0));
size_t n = 4;
INTEGERS<4> p2;
foo(p2, INTEGERS<4>::TypeTrait*(0));
}
I hope all INTEGERS<1>...type can use the specilization for template
function foo(....). I think the compiler could get that
HrtTypes<enumINTEGER> is same with INTEGERS<1>::TypeTrait, so foo(p1,
INTEGERS<1>::TypeTrait*(0)) and foo(p2, INTEGERS<4>::TypeTrait*(0));
can call the same function above.
but it seems these not works.
who can give me more comments
Thanks very well.