类模板中的函数模板的定义和调用(不是模板类中的普通成员函数)

来源:互联网 发布:咨询师网络教育平台 编辑:程序博客网 时间:2024/05/16 17:55
#include <iostream>using namespace std;template<typename T>struct A {virtual void foo();// error: templates may not be ‘virtual’template<typename X>/* virtual */ void bar();};template<typename T>void A<T>::foo() {}template<typename T>template<typename X>void A<T>::bar() {}int main() {A<int> a1;a1.foo();a1.bar<double>();}

原创粉丝点击