I_ren 2020-07-08 17:14 采纳率: 50%
浏览 77
已采纳

c++ 模板类继承中unresolved externals问题

template <typename T>
class Father
{
public:
    Father() = default;

    ~Father() = default;

    void function();
};

class Child : Father<int>
{
public:
   Child();
     ~Child() = default;
}

Child::Child()
{
   function();    //报错
}
  • 写回答

1条回答 默认 最新

  • threenewbee 2020-07-08 17:27
    关注
    #include <iostream>
    
    using namespace std;
    
    template <typename T>
    class Father
    {
    public:
        Father() = default;
    
        ~Father() = default;
    
        void function(){}
    };
    
    class Child : Father<int>
    {
    public:
       Child();
       ~Child() = default;
    };
    
    Child::Child()
    {
       Father<int>::function();  
    }
    
    int main() {
        return 0;
    }
    
    

    问题解决的话,请点下采纳

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?