Error: attempting to reference a deleted function

I’m following Part 2 of the C++ course, Operator Overloading.

Can anyone help, please?

ostream operator<<(ostream &stream, const Movie &movie)
{
stream << movie.title;
return stream; // this line here is giving me an error
}

C:\Users\Stephen\Documents\Code\hellowworld\part2.cpp(352): error C2280: ‘std::basic_ostream<char,std::char_traits>::basic_ostream(const std::basic_ostream<char,std::char_traits> &)’: attempting to reference a deleted function
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\ostream(64): note: see declaration of ‘std::basic_ostream<char,std::char_traits>::basic_ostream’
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\ostream(64): note: ‘std::basic_ostream<char,std::char_traits>::basic_ostream(const std::basic_ostream<char,std::char_traits> &)’: function was explicitly deleted

Found my error:
ostream& operator<<(ostream &stream, const Movie &movie)

I was missing the & symbol to return ostream as a reference.

1 Like

Congratulations @stephensaid for identifying the error! Great job! Keep it up!