In the following snippet of code the compiler (g++ on RH 4) does not see my overloaded operator. I cannot figure out why.
Error:
parse_opra.cpp: In function `void parseFile(std::istream&)':
parse_opra.cpp:19: error: no match for 'operator>>' in 'in >> rec'
note: candidates are: std::basic_istream<_CharT,......
.....
opra_record.h:35: note: std::istream& operator>>(std::istream&, Opra_record&)
I am especially confused by the last candidate (above) as that is what I am looking for...??
Thanks in advance for any clarification.
Steve
//opra_record.h
class Opra_record {
friend std::ifstream& operator>>(std::ifstream&, Opra_record&);
private:
std::vector<std::string> stringData;
std::vector<long> numericData;
std::string temp;
public:
typedef std::vector<std::string>::size_type size_type;
Opra_record();
Opra_record(const Opra_record&);
~Opra_record();
Opra_record(const std::vector<std::string>&);
size_type size() const;
std::string& operator[] (size_type i);
const std::string& operator[] (size_type i) const;
};
std::ifstream& operator>>(std::ifstream&, Opra_record&);
//parse_opra.cpp
#include "opra_record.h"
void parseFile(ifstream& in)
{
string tmp;
Opra_record* rec = new Opra_record;
while(!in.eof()) {
in >> rec; ///***************here
}
}
int main(int argc, char** argv){
if (argc < 2)
return(EXIT_FAILURE);
ifstream in(argv[1]);
if(!in)
return(EXIT_FAILURE);
parseFile(in);
}