0

I really need some help. My << operator in my class does not work, but i don't know why. I get errors like: "function text skipped" and "too many parameters". The Print()-function works. But the operator << is the problem.

int main(){

    Set<int> s;
    s.Add(1);
    s.Add(9);
    cout << s;

}



template <typename T>
class Set {
public:

    //Hinzufügen eines Elements
    bool Add(T const &x) { return mSet.insert(x).second; }

    //Entfernen eines Elements
    bool Remove(T const &x) { return mSet.erase(x) > 0; }

    //Prüfen, ob Wert enthalten ist
    bool Contains(T const &x) { return mSet.count(x) > 0; }


    //Ausgabe auf einen Stream
    void Print(std::ostream &out) const{
        std::for_each(mSet.begin(), mSet.end(), [&out](const T elem) { out << elem << "\n"; });
    }

    //ruft einfach Print auf
    std::ostream& operator<<(std::ostream& out, const Set<T> & obj)
    {
        obj.Print(out);
        return out;
    }

private:
    std::set<T> mSet;

};

Is anyone able to fix the problem? I'm really despairing...

0 Answers0