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<enumIN TEGERTypeTrait;
enum { size = _size };
};
template<typena me T>
bool foo(T*, typename T::TypeTrait*);
//specializaton for INTEGERS<1>,<2> , ...<n>
template<typena me T>
bool foo(T*, HrtTypes<enumIN TEGER>*)
{
return true;
}
int main()
{
INTEGERS<1>* p1;
foo(p1, INTEGERS<1>::Ty peTrait*(0));
size_t n = 4;
INTEGERS<4p2;
foo(p2, INTEGERS<4>::Ty peTrait*(0));
}
I hope all INTEGERS<1>...t ype can use the specilization for template
function foo(....). I think the compiler could get that
HrtTypes<enumIN TEGERis same with INTEGERS<1>::Ty peTrait, so foo(p1,
INTEGERS<1>::Ty peTrait*(0)) and foo(p2, INTEGERS<4>::Ty peTrait*(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<enumIN TEGERTypeTrait;
enum { size = _size };
};
template<typena me T>
bool foo(T*, typename T::TypeTrait*);
//specializaton for INTEGERS<1>,<2> , ...<n>
template<typena me T>
bool foo(T*, HrtTypes<enumIN TEGER>*)
{
return true;
}
int main()
{
INTEGERS<1>* p1;
foo(p1, INTEGERS<1>::Ty peTrait*(0));
size_t n = 4;
INTEGERS<4p2;
foo(p2, INTEGERS<4>::Ty peTrait*(0));
}
I hope all INTEGERS<1>...t ype can use the specilization for template
function foo(....). I think the compiler could get that
HrtTypes<enumIN TEGERis same with INTEGERS<1>::Ty peTrait, so foo(p1,
INTEGERS<1>::Ty peTrait*(0)) and foo(p2, INTEGERS<4>::Ty peTrait*(0));
can call the same function above.
but it seems these not works.
who can give me more comments
Thanks very well.
Comment