我正在尝试调用一个显示结构变量内容的 void 函数,但是在调用该函数时出现此错误。
invalid operands of types 'void' and '<unresolved overloaded function type>' to binary 'operator
老实说,我是 C++ 新手,我不明白错误的含义。我该如何解决?
#include <iostream>
using namespace std;
struct MovieData
{
string title;
string director;
int yearReleased;
int runningTimeInMinutes;
};
void showMovieData(MovieData movie);
int main()
{
MovieData apocalypseNow = {"Apocalypse Now", "Francis Ford Coppola", 1979, 153};
MovieData theWizardOfOz = {"The Wizard of Oz", "Victor Fleming", 1939, 101};
//error occurs here
showMovieData(apocalypseNow) << endl;
showMovieData(theWizardOfOz) << endl;
}
void showMovieData(MovieData movie)
{
cout << "Title: " << movie.title << endl;
cout << "Director: " << movie.director << endl;
cout << "Year Released: " << movie.yearReleased << endl;
cout << "Running Time (in minutes): " << movie.runningTimeInMinutes << endl;
}