emplate />::yes <:string><:complex<:complex<:endl; <:endl; <:endl; <:endl; <:endl; <:endl; <:string><:endl; <:complex<:endl; <:complex<:endl; <:complex<:string><:complex<:complex<:string><:complex<:complex<< std::endl; std::cout << "Derived5 is kind of AnotherTemplate? " <:string><:complex<:complex<:endl; <:endl; <:endl; <:endl; <:endl; <:endl; <:string><:endl; <:complex<:endl; <:complex<:endl; <:complex<:string><:complex<:complex<:string><:complex<:complex<< is_kind_of::yes << std::endl;vDTLinux联盟 std::cout << "Derived6 is kind of AnotherTemplate? " <:string><:complex<:complex<:endl; <:endl; <:endl; <:endl; <:endl; <:endl; <:string><:endl; <:complex<:endl; <:complex<:endl; <:complex<:string><:complex<:complex<:string><:complex<:complex<< is_kind_of::yes << std::endl;vDTLinux联盟 std::cout << "Derived7 is kind of AnotherTemplate? " <:string><:complex<:complex<:endl; <:endl; <:endl; <:endl; <:endl; <:endl; <:string><:endl; <:complex<:endl; <:complex<:endl; <:complex<:string><:complex<:complex<:string><:complex<:complex<< is_kind_of::yes << std::endl;vDTLinux联盟 std::cout << "Derived8 is kind of AnotherTemplate? " <:string><:complex<:complex<:endl; <:endl; <:endl; <:endl; <:endl; <:endl; <:string><:endl; <:complex<:endl; <:complex<:endl; <:complex<:string><:complex<:complex<:string><:complex<:complex<< is_kind_of::yes << std::endl;vDTLinux联盟 std::cout << "Derived9 is kind of AnotherTemplate? " <:string><:complex<:complex<:endl; <:endl; <:endl; <:endl; <:endl; <:endl; <:string><:endl; <:complex<:endl; <:complex<:endl; <:complex<:string><:complex<:complex<:string><:complex<:complex<< is_kind_of::yes << std::endl;vDTLinux联盟 return 0;vDTLinux联盟 }vDTLinux联盟 #endif//CODE3vDTLinux联盟 ///////////////////////////////////////////////////////////////vDTLinux联盟 //该程序的运行结果如下:vDTLinux联盟 /*************************************************************vDTLinux联盟 Derived1 is kind of Template? 1vDTLinux联盟 Derived2 is kind of Template? 1vDTLinux联盟 Derived3 is kind of Template? 1vDTLinux联盟 Derived4 is kind of Template? 1vDTLinux联盟 Derived5 is kind of Template? 1vDTLinux联盟 Derived6 is kind of Template? 1vDTLinux联盟 Derived7 is kind of Template? 1vDTLinux联盟 Derived8 is kind of Template? 1vDTLinux联盟 Derived9 is kind of Template? 1vDTLinux联盟 Derived1 is kind of AnotherTemplate? 0vDTLinux联盟 Derived2 is kind of AnotherTemplate? 0vDTLinux联盟 Derived3 is kind of AnotherTemplate? 0vDTLinux联盟 Derived4 is kind of AnotherTemplate? 0vDTLinux联盟 Derived5 is kind of AnotherTemplate? 0vDTLinux联盟 Derived6 is kind of AnotherTemplate? 0vDTLinux联盟 Derived7 is kind of AnotherTemplate? 0vDTLinux联盟 Derived8 is kind of AnotherTemplate? 0vDTLinux联盟 Derived9 is kind of AnotherTemplate? 0vDTLinux联盟 ****************************************************************/vDTLinux联盟 ////////////////////////////////////////////////////////////////vDTLinux联盟 #if 0vDTLinux联盟 vDTLinux联盟 从CODE3的运行结果可以看出:我们已经成功的实现了判断某个型别是否是某个模板类vDTLinux联盟 的派生类或者是直接实例化的类的能力。因此我们就可以在自己编写代码的时候利用这些vDTLinux联盟 功能来实现静态分派的能力。vDTLinux联盟 vDTLinux联盟 至于第三种方法已经在前面的章节中讨论过了。根据索引号访问scatter产生的代码的vDTLinux联盟 同类型变量的方法就是采用了第三种方法。vDTLinux联盟 vDTLinux联盟 到目前为止,已经讨论了我所知道的C++里面的类型识别的一般方法。具体如何应用就要vDTLinux联盟 看您的发挥了。我编写的撤销和重做库中就采用了这里的方法来识别简单类型和复合类型的。vDTLinux联盟 vDTLinux联盟 #endif
|