Не удается перегрузить поток вывода в C++

Я пытаюсь перегрузить оператор << в моем классе STEntry, но продолжаю сталкиваться с этой ошибкой. Мой класс вставлен ниже ошибки.

stentry.h: In function ‘std::ostream& operator<<(std::ostream&, const STEntry&)’:
stentry.h:48: error: no match for ‘operator<<’ in ‘std::operator<< [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((std::basic_ostream<char, std::char_traits<char> >&)((std::basic_ostream<char, std::char_traits<char> >*)out)), ((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)(& temp->STEntry::lexeme))) << ','’
stentry.h:46: note: candidates are: std::ostream& operator<<(std::ostream&, const STEntry&)

Мой класс в STEntry.h. Он довольно прост. Я пытаюсь вывести на экран значения некоторых переменных.

#ifndef __STENTRY__
#define __STENTRY__
#include <string>

using namespace std;

class STEntry {
  public:
     string lexeme; // addr. of lexema associated with this entry
     int  tokenval; // token value for this entry
     int  offset;   // location of variable in block

     STEntry(string name = "", int newval = 0, int newoffset = 0);
     // function:  constructor ... initializes major fields

     // Relational operators:
    bool operator == (const STEntry &) const;
    bool operator != (const STEntry &) const;
    friend ostream & operator << (ostream &, const STEntry &);
};

//--- BEGIN IMPLEMENTATION

//constructor
STEntry::STEntry(string name, int newval, int newoffset)
{
    lexeme = name;
    tokenval = newval;
    offset = newoffset;
}

// ....

//Output a single STEntry to standard output
std::ostream& operator << (std::ostream& out, const STEntry & temp)
{
    out << temp.lexeme << ',' << temp.tokenval << ',' << temp.offset;
    return out;
}

//--- END OF IMPLEMENTATION
#endif
0
задан sri 29 January 2012 в 02:38
поделиться