0

Trying to have a print function inside a class to print declared variables.

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)"; } }; 

Error comes out to this:

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(); 

1 Answer 1

5

You need parentheses after print as well as a return type, like so: void print() {...}.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks i'm in the process of the learn cPP this was my first ever class written in c++ i should have seen that it just slipped my mind for some reason. thanks :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.