jeudi 21 janvier 2021

std::ostream object in class is "not accessible through a pointer or object"

I use several functions in a class, which are passed an ostream via the function interface, which in turn can be used to output error messages. I had hoped to be able to bind all ostreams to a single object that I then redirect to a file if necessary.

The relevant parts of my code look something like this:

#include <iostream>

class Example
{
    public:
    Example(){} //<--Error: "std::basic_ostream<_CharT, _Traits>::basic_ostream() [with _CharT=char, _Traits=std::char_traits<char>]" (declared at line 390 of "/usr/include/c++/9/ostream") is inaccessible C/C++(330)

    void DoSomething()
    {
        FunctionWithOstream(out);
    }

    private:
    std::ostream out; //in my case, the ostream is currently not needed for the time being.

    void FunctionWithOstream(std::ostream& out)
    {
        out << "Something";
    }
};

At the first curly bracket of the constructor (or all constructors in the program) I get the following error message:

protected function "std::basic_ostream<_CharT, _Traits>::basic_ostream() [with _CharT=char, _Traits=std::char_traits]" (declared at line 390 of "/usr/include/c++/9/ostream") is not accessible through a "std::basic_ostream<char, std::char_traits>" pointer or objectC/C++(410)

or for the short excample code i pasted here:

"std::basic_ostream<_CharT, _Traits>::basic_ostream() [with _CharT=char, _Traits=std::char_traits]" (declared at line 390 of "/usr/include/c++/9/ostream") is inaccessibleC/C++(330)

I hope the question is clear enough and thank you in advance for your time.

Greetings Tillman

Aucun commentaire:

Enregistrer un commentaire