标题:
#ifndef patientenliste_hpp
#define patientenliste_hpp
#include <vector>
#include <iostream>
#include "patient.hpp"
using namespace std;
class Patientenliste
{
private:
vector<Patient> liste;
public:
Patientenliste& operator+= (const Patient&);
friend ostream& operator<< (ostream&, const Patientenliste&);
};
ostream& operator<< (ostream&, const Patientenliste&);
#endif
源代码:
#include "patientenliste.hpp"
Patientenliste::Patientenliste& operator+= (const Patient& p)
{
liste.push_back(p);
return *this;
}
ostream& operator<< (ostream& os, const Patientenliste& p)
{
for(auto& i : p.liste)
os << i;
return os;
}
为什么我必须在源代码的运算符定义 += 中的“liste”之前放置“Patientenliste::”? Eclipse 无法解决它,但它应该可以,不是吗? 在我之前的项目中工作得很好...
最佳答案
这个
Patientenliste::Patientenliste& operator+= (const Patient& p)
应该是
Patientenliste& Patientenliste::operator+= (const Patient& p)
您正在使用 Patientenliste::
,因为 operator+= 在该类的范围内,即该类的成员。
关于c++ - Eclipse c++ 方法无法解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26847916/