![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
template< typename T, typename TT >
class ErrorGenerator2
{
// const int errorGen=0; - this is underfined! :-)
};
template < typename T>
class ExactType
{
T mT;
public:
ExactType(T t)
: mT(t)
{}
template < typename TT >
ExactType(TT tt)
{
ErrorGenerator2< T, TT>::errorGen; // error generator: 2nd type is disallowed, use 1st only
}
T get()
{ return mT; }
};
void funcExact(ExactType< int > arg)
{
}
enum ESomeEnum { aaa};
void test()
{
funcExact(aaa);
short si=1;
funcExact(si);
}
Таким трюком можно, например, защищать конструкторы классов, принимающие один целый аргумент.
Решение не очень практичное, поскольку имеет ряд недостатков.
class ErrorGenerator2
{
// const int errorGen=0; - this is underfined! :-)
};
template < typename T>
class ExactType
{
T mT;
public:
ExactType(T t)
: mT(t)
{}
template < typename TT >
ExactType(TT tt)
{
ErrorGenerator2< T, TT>::errorGen; // error generator: 2nd type is disallowed, use 1st only
}
T get()
{ return mT; }
};
void funcExact(ExactType< int > arg)
{
}
enum ESomeEnum { aaa};
void test()
{
funcExact(aaa);
short si=1;
funcExact(si);
}
Таким трюком можно, например, защищать конструкторы классов, принимающие один целый аргумент.
Решение не очень практичное, поскольку имеет ряд недостатков.