dogma897
dogma897

Reputation: 31

What can i return if i'm working with a pointer on a const function?

class class_B
{
    class_A* A;

.
.
.

    class_A& func() { return *A; }
    class_A func() const { return *A; }

ostream& operator <<(ostream& os, const class_B& obj)
{
    os << obj.func();
    return os;
}

this give me an error but i don't understand why.

Do I have to implement class_A's copy/move constructor/operator?

Upvotes: 0

Views: 43

Answers (1)

gct
gct

Reputation: 14563

Return a const reference:

const class_A& func() const { return *A; }

Upvotes: 2

Related Questions