c++ - Eclipse c++ 方法无法解析

标签 c++ methods resolve

标题:

#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/

相关文章:

c++ - 如何在不将查找表加载到内存的情况下对查找表执行搜索?

c++ - 我什么时候需要实现 operator [] ?

javascript - 方法与函数,以及其他问题

java - 第一次使用数组,尝试创建频率表

C++17 部分推导指南

C++ Vector 比计算几何中的 Vector 修改了两次

java - 调用方法时找不到符号

java - BarcodeScanner - 无法解析方法resumeCameraPreview

intellij-idea - IntelliJ在集成测试(Gradle项目)中不使用JUnit导入

Python socket.gethostbyname_ex() 多线程失败