Шаблоны.. помогите разобраться..
От: alexsy Россия  
Дата: 06.06.08 07:55
Оценка:
Продолжаю изкчать.. шаблоны по книге "Вандевурд, Джосаттис — Шаблоны C++"
вот в стретил пример из книги..

#include <iostream>
#include <string>

template< typename Type >
class CIsClass {
    typedef char first;
    typedef struct { char dummu[ 2 ]; } second;
    template< typename TypeClass >
    static first test( int TypeClass::* ){ return first(); };
    template< typename TypeClass >
    static second test( ... ){ return second(); };
public:
    enum { Yes = sizeof( CIsClass<Type>::test<Type>(0) ) == 1 };
    enum { No = !Yes };
};
//*****************************************************************************
class CClass{
};
//*****************************************************************************
struct CStruct{
};
//*****************************************************************************
union CUnion{
};
//*****************************************************************************
void finc(){
}
//*****************************************************************************
enum E{ e1 } e;
//*****************************************************************************
//*****************************************************************************
template< typename Type >
std::string Check(){
    return CIsClass< Type >::Yes ? " It is Class." : " It is not Class.";
}
//*****************************************************************************
//*****************************************************************************
template< typename Type >
void CheckType( Type ){
    Check<Type>();
}
//*****************************************************************************
//*****************************************************************************
CStruct s;
int main() {
    // prints test_template_IsClass
    std::cout << "test_template_IsClass" << std::endl;
    std::cout << "int: " <<  Check< int >() << std::endl;
    return 0;
}


не компилит в строке enum { Yes = sizeof( CIsClass<Type>::test<Type>(0) ) == 1 }; говарит error: expected primary-expression before ‘>’ token
в чём дело?? Или тут чисто тиория..
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.