Why does only first implementation work and not the other implementations specified below, Can someone explain the way this template structure work and why others do not.
Template structures that work
template <typename T, typename U>
struct is_same
{
static const bool value = false;
};
template <typename T>
struct is_same<T, T>
{
static const bool value = true;
};
Template structures that do not work
template <typename T, typename U>
struct is_same<T, U>
{
static const bool value = false;
};
template <typename T>
struct is_same<T, T>
{
static const bool value = true;
};
One more that does not work
template <typename T, typename U>
struct is_same<T,U>
{
static const bool value = false;
};
template <typename T>
struct is_same
{
static const bool value = true;
};
And the Main Function
template <class A, class B>
bool IsSameClass() {
return is_same<A, B>::value;
}
int main()
{
bool ret = IsSameClass<P,C>();
}