Domanda

template<int, int> 
struct T;

template<> 
struct T<?, ?> {};

i want this to work

typedef T<1, 0> t;

and this to cause compile time error

typedef T<1, 2> t;

EDIT, i mean i want second parameter to be 0. and i can't use C++11 features.

È stato utile?

Soluzione

Your quesiton is not too clear. Are you looking for this?

template <int, int>
struct T;

template<int x>
struct T<x, 0>
{
  // Definition of the struct for the allowed case
};

Altri suggerimenti

You can use static_assert to assert the template arguments.

template<int A, int B> 
struct T
{
   static_assert(A > B, "Raised error because A is not bigger than B)";
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top