我的代码中的“friend”函数有问题,你能帮我解决吗?

问题描述 投票:0回答:1

当我使用模板时,“friend”函数出错。我不明白。请您帮我解释一下吗?

#include<iostream>

using namespace std;

template<class T>
class sophuc

{
    public:
       
        sophuc(T new_thuc, T new_ao);
        void fill();
        void Display();
        sophuc();
        friend sophuc sum_(sophuc &a, sophuc &b);
    private:

        T thuc, ao;        
};

希望有人尽快解决我。

c++ oop templates friend
1个回答
0
投票

您可能希望将友元函数移动为私有,使其仅在声明类 sophuc 的类和函数中可用。

© www.soinside.com 2019 - 2024. All rights reserved.