Funkcja przyjaciela C ++ nie może uzyskać dostępu do członków prywatnych

Ma to być klasa łańcuchowa z wieloma operatorami i funkcjami, w tym dwie funkcje przyjaciela. A te dwa powodują dla mnie pewne kłopoty, ponieważ kompilator mówi, że nie mogą uzyskać dostępu do prywatnych członków. Oto mój ciąg.h:

#include <iostream>
#ifndef STR_H
#define STR_H

namespace MyStr
{
class Str
{
private:
    unsigned int length;
    char *data;
public:
    Str();
    Str(const Str&);
    Str(const char*);
    Str(char c, unsigned int db);
    ~Str();
    char* cStr() const;
    unsigned int getLength() const;

wiele nieistotnych funkcji tutaj ...

    friend int operator/ (const Str&, char);
    friend std::ostream& operator<< (std::ostream&, const Str&);
};
}
#endif /* STR_H */

tutaj jest main.cpp:

#include <iostream>
#include "Str.h"

using namespace std;
using namespace MyStr;

ostream& operator<< (ostream& out,const Str& str)
{
    for (int i=0; i<str.length; i++)
    {
        out<<str.data[i];
    }
    out<<endl;
    return out;
}

int operator/ (const Str& str, char c)
{
    for (int i=0; i<str.length; i++)
    {
        if(str.data[i]==c) return i;
    }
    return -1;
}

Ten kod nie będzie się kompilował, kompilator twierdzi, żeStr członkowie są prywatni.

questionAnswers(2)

yourAnswerToTheQuestion