yigal_s: (Default)
[personal profile] yigal_s
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);
}

Таким трюком можно, например, защищать конструкторы классов, принимающие один целый аргумент.
Решение не очень практичное, поскольку имеет ряд недостатков.
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting