C++ `运营商>&燃气轮机';不是'Instance';

C++ `运营商>&燃气轮机';不是'Instance';,c++,compiler-errors,C++,Compiler Errors,我有一个包含Instance.h头的InstancePool类(下面是它的一部分),但是我在InstancePool的操作符>函数的标题中得到了错误 #include <iostream> #include <string> #include <vector> #include <map> #include <sstream> #include <stdlib.h> using namespace std; #inclu

我有一个包含Instance.h头的
InstancePool
类(下面是它的一部分),但是我在
InstancePool
操作符>
函数的标题中得到了错误

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <stdlib.h>

using namespace std;

#include "Instance.h"
#include "InstancePool.h"

istream &operator >> (istream &in , InstancePool &ip) {

    ip.Instances->clear();

    string input;
    getline(in , input);

    while (!in.eof()) {

        Instance inst;

        Instance::operator >>(in , inst); // <- line giving me the error

        ip.Instances->push_back(inst);

        getline(in , input);

    }
}
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
#包括“Instance.h”
#包括“InstancePool.h”
istream和operator>>(istream和in、InstancePool和ip){
实例->清除();
字符串输入;
getline(in,输入);
而(!in.eof()){
实例研究所;
实例::运算符>>(in,inst);//推回(inst);
getline(in,输入);
}
}
InstancePool操作符>>函数是一个“朋友”函数,在实例中也是如此。可能我试图以错误的方式访问实例“operator>>”,但如果我知道正确的,我会被诅咒。。。
有什么帮助吗?

朋友函数不是成员函数,您不能像以前那样显式限定函数名,因为它根本不在名为
实例的命名空间中

好消息是:你不需要这样做。正常地说:

in >> inst;
不过,您的代码中还有更多的bug。首先,当读取时出错时,
while(in.eof())
将导致无限循环–决不执行此操作


其次,您正在使用
getline
读取和丢弃行。这可能不是你想做的,对吧?您想从行中还是直接从输入流中读取每个实例?

友元函数不是成员函数,您不能像这样显式地限定函数名,因为它根本不在名为
实例
的命名空间中

好消息是:你不需要这样做。正常地说:

in >> inst;
不过,您的代码中还有更多的bug。首先,当读取时出错时,
while(in.eof())
将导致无限循环–决不执行此操作


其次,您正在使用
getline
读取和丢弃行。这可能不是你想做的,对吧?您想从行中还是直接从输入流中读取每个实例?

是的,我认为使用eof()会导致非常糟糕的结果。。我认为我应该直接从iput流中阅读。有什么建议吗?谢谢你的时间@user2055832是,直接在循环中读取:
Instance inst;while(在>>指令中)ip.Instances->push_back(指令)可能会起作用,这取决于对象是如何单独读取的。嗯,我明白了。我会用这种方式尝试,如果有问题,我会向你汇报!非常感谢。是的,我认为使用eof()会导致非常糟糕的结果。。我认为我应该直接从iput流中阅读。有什么建议吗?谢谢你的时间@user2055832是,直接在循环中读取:
Instance inst;while(在>>指令中)ip.Instances->push_back(指令)可能会起作用,这取决于对象是如何单独读取的。嗯,我明白了。我会用这种方式尝试,如果有问题,我会向你汇报!非常感谢。