尝试在类中使用print函数来打印声明的变量.
class MovieData{
private:
int year, runtime;
string title, director;
public:
MovieData(string t, string d, int y, int rt){
year = y;
runtime = rt;
title = t;
director = d;
}
print{
cout << title << " (" << year << "). Directed by " << director << ". (" << rt << " minutes)";
}
};
Run Code Online (Sandbox Code Playgroud)
错误出现了:
main.cpp:20:9: error: ‘print’ does not name a type
print{
^
main.cpp: In function ‘void doIt(std::string, std::string, int, int)’:
main.cpp:33:5: error: ‘class MovieData’ has no member named ‘print’
md.print();
Run Code Online (Sandbox Code Playgroud)