K
kuangye
How to walk around this compilation error?
////////////////////////////
template<bool flag>
class COMPILER_STATIC_CHECK{
};
template<>
class COMPILER_STATIC_CHECK<true>{
public:
enum{OK=1,};
public:
COMPILER_STATIC_CHECK(...){}
};
#define STATIC_CHECK_BY_EVAL(CheckName, cnstExprVal)\
enum {CheckName= COMPILER_STATIC_CHECK<((bool)(cnstExprVal))
enum STID
{
I32ID=1,
F32ID=20,
};
template<STID tid>
class Scalar;
template<typename T>
class Complex;
template<STID tid>
class Scalar
{
public:
typedef Scalar SelfType;
static const STID tid = tid;
SelfType operator+(const SelfType&)
{
return *this;
}
Complex<SelfType> operator+(const Complex<SelfType>& src);
};
template<typename T>
class Complex
{
//////////////////////////////check
////I need this check to forbidden programmer to instantiate
Complex<I32>
////
STATIC_CHECK_BY_EVAL(TShouldBeF, T::tid==20);
///////////////////////////
public:
typedef Complex SelfType;
};
template<STID tid>
Complex< Scalar<tid> > Scalar<tid>:perator+(const Complex<SelfType>&
src2)
{
return src2;
}
typedef Scalar<I32ID> I32;
typedef Scalar<F32ID> F32;
int main()
{
I32 i1, i2, i3;
i1 + i2;
return 0;
}
compilation error message:
=========================
error C2039: 'OK' : is not a member of 'COMPILER_STATIC_CHECK<flag>'
[
flag=false
]
see reference to class template instantiation 'Complex<T>' being
compiled
with
[
T=S
]
=========================
Seems that finding the candidate functions will cause class template
instantiation.
How to bypass this compilation error
////////////////////////////
template<bool flag>
class COMPILER_STATIC_CHECK{
};
template<>
class COMPILER_STATIC_CHECK<true>{
public:
enum{OK=1,};
public:
COMPILER_STATIC_CHECK(...){}
};
#define STATIC_CHECK_BY_EVAL(CheckName, cnstExprVal)\
enum {CheckName= COMPILER_STATIC_CHECK<((bool)(cnstExprVal))
::OK, };
enum STID
{
I32ID=1,
F32ID=20,
};
template<STID tid>
class Scalar;
template<typename T>
class Complex;
template<STID tid>
class Scalar
{
public:
typedef Scalar SelfType;
static const STID tid = tid;
SelfType operator+(const SelfType&)
{
return *this;
}
Complex<SelfType> operator+(const Complex<SelfType>& src);
};
template<typename T>
class Complex
{
//////////////////////////////check
////I need this check to forbidden programmer to instantiate
Complex<I32>
////
STATIC_CHECK_BY_EVAL(TShouldBeF, T::tid==20);
///////////////////////////
public:
typedef Complex SelfType;
};
template<STID tid>
Complex< Scalar<tid> > Scalar<tid>:perator+(const Complex<SelfType>&
src2)
{
return src2;
}
typedef Scalar<I32ID> I32;
typedef Scalar<F32ID> F32;
int main()
{
I32 i1, i2, i3;
i1 + i2;
return 0;
}
compilation error message:
=========================
error C2039: 'OK' : is not a member of 'COMPILER_STATIC_CHECK<flag>'
[
flag=false
]
see reference to class template instantiation 'Complex<T>' being
compiled
with
[
T=S
]
=========================
Seems that finding the candidate functions will cause class template
instantiation.
How to bypass this compilation error