在这种情况下我们可以使用 static 而不是 friend 吗?其他解决方案是什么

can we use static instead of friend in this case and what are the other solutions

当我在 PhoneNumber.h 中使用 friend 作为运算符函数时,PhoneNumber.cpp 表现良好。但是对于 static 它不能被编译(为什么?)以及声明它的其他方法是什么(即)除 friend 之外的所有方法。

PhoneNumber.h

#include<iostream>
#include <string>
#include<iomanip>
using namespace std;
class PhoneNumber{
    public:
    string areaCode, exchange, line;
    static ostream& operator<<(ostream &output, const PhoneNumber&);
    static istream& operator>>(istream &input, PhoneNumber&);
};

PhoneNumber.cpp

#include"PhoneNumber.h"
using namespace std;

ostream& PhoneNumber::operator<<(ostream &output, const PhoneNumber& obj){
    output << "(" <<obj. areaCode << ") "
    << obj.exchange << "-" << obj.line;
    return output;
};


istream& PhoneNumber::operator>>(istream &input, PhoneNumber&obj){

    input.ignore(); 
    input >> setw( 3 ) >> obj.areaCode;
    input.ignore( 2 );
    input >> setw( 3 ) >> obj.exchange;
    input.ignore();
    input >> setw( 4 ) >> obj.line;
    return input;
    };

main.cpp

#include"PhoneNumber.h"
using namespace std;

int main(){

PhoneNumber phone;
 cout << "Enter phone number in the form (123) 456-7890:" << endl;
cin>>phone;
cout << "The phone number entered was: ";
cout<<phone;cout << endl;
int y;cin>>y;
return 0;}

重载运算符不能是静态成员函数,参见[over.oper](重点是我的)。

An operator function shall either be a non-static member function or be a non-member function that has at least one parameter whose type is a class, a reference to a class, an enumeration, or a reference to an enumeration.