0

Compilation error and nested classes

Why is the code below returning a compilation error? #include <iostream> using namespace std; class engine { public: bool run() { starter starter; starter.start(); return starter.isRunning(); } class starter { public: void start() { running=true; } bool isRunning() { return running; } private: bool running=false; }; }; int main() { engine engine; cout << engine.run; }

19th May 2017, 5:27 PM
Space Turtlez
Space Turtlez - avatar
2 odpowiedzi
+ 1
You forgot the () after run: cout << engine.run(); Also consider making your class start with a capital, this just hurts my eyes :( So engine -> Engine and starter -> Starter
19th May 2017, 5:57 PM
Dennis
Dennis - avatar
0
Thanks, it works now. When I resume working with the language, I'll make my code neater and more organized.
23rd May 2017, 12:01 PM
Space Turtlez
Space Turtlez - avatar