Operatorüberladung - friend - error



  • // HEADER
    class Token
    {
    private:
      Type myType;
      std::string myValue;
    
    public:
      Token(Type type = Token, const std::string& value);
    
      friend bool operator==(Type type, const Token& token);
    };
    
    // SOURCE
    bool operator==(Type type, const Token& token)
    {
      return type == token.myType; // error: ‘Type Token::myType’ is private
    }
    

    Ich habs doch als friend deklariert? Warum dann "error: ‘Type Token::myType’ is private"?

    Bin am Verzweifeln...



  • Hallo

    Bin mir wzar nicht sicher ob es hilft, aber kann es sein das du irgendwo doppelte Namen verwendest, wenn ich mir alleine dieses Stückchen anschau:

    Token(Type type = Token, const std::string& value);
    

    Was ist hier das "= Token"? Bzw. welcher Datentyp ist Type? Enumeration?

    Mfg marco



  • Auch wenn ich das wegnehme, bleibt der Fehler bestehen.



  • Zeig mal ein komplettes Beispiel!

    Das hier kompiliert bei mir ohne Probleme (MSVC++2008)

    typedef int Type;
    
    // HEADER
    class Token
    {
    private:
      Type myType;
      std::string myValue;
    public:
      friend bool operator==(Type type, const Token& token);
    };
    
    // SOURCE
    bool operator==(Type type, const Token& token)
    {
      return type == token.myType; // error: ‘Type Token::myType’ is private
    }
    
    int main()
    {
    }
    

Anmelden zum Antworten