小编leJ*_*Jon的帖子

C++ 继承和模板函数

我想知道是否有继承模板函数的模式/方法?模板函数不能是虚拟的,因此如果我的基类有模板函数并且我的派生类也有相同的模板函数,则在以下示例中将始终调用基类的函数:

struct Base {
    Base() {}
    template < typename T >
    void do_something(T&  t) const {
        t << "Base" << std::endl ;
    }
    };

struct Foo : Base {
    Foo() : Base () {}
    template < typename T >
    void do_something(T&  t) const {
        t << "Foo" << std::endl ;
    }
};

struct Bar : Foo {
    Bar() : Foo() {}
    template < typename T >
    void do_something(T&  t) const {
        t << "Bar" << std::endl ;
    }
};


int …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance templates

6
推荐指数
1
解决办法
6357
查看次数

线程工作目录

根据定义,单个程序的多个线程共享它们的工作目录。您是否知道是否可以将每个线程都放在专用的工作目录中?也许是一个特定的图书馆?

注意:目标语言是c ++

c++ multithreading c++11

5
推荐指数
2
解决办法
1120
查看次数

标签 统计

c++ ×2

c++11 ×1

inheritance ×1

multithreading ×1

templates ×1