C++ template class specialization: why do common methods need to be re-implemented

后端 未结 5 785
心在旅途
心在旅途 2021-02-19 06:32

In the sample:

#include 

using namespace std;

class B
{
public:
    virtual void pvf() = 0;
};

template 
class D : public B
{
p         


        
5条回答
  •  孤城傲影
    2021-02-19 07:01

    Consider that D::D() will be responsible for default-constructing string data, and that D doesn't have any such member. Clearly there is no way to use the same emitted code in each case.

    However, if your default constructor doesn't do anything (in either version here), just omit it and allow the compiler to do the work.

提交回复
热议问题