+ 2

How do you solve this issue with class and inheritance in separate files?

I had this error.. when i used uses inheritance in 2 separate files.. I did the inheritance thing in the header file.. so the first header file class MyFirstClass{ public: there's a constructor and a destructor here.. } so the second header file . class MySecondClass : public MyFirstClass{ constructor and destructor } when I build all the three files.. the 2 separate classes and the main.cpp file.. error : expected class-name before '{' token class MySecondClass {

22nd Feb 2018, 6:57 PM
Otumian Empire
Otumian Empire - avatar
4 Antworten
+ 6
first header second header #include "MyFirstClass.h" first source #include "MyFirstClass.h" second source #include "MyFirstClass.h" #include "MySecondClass.h" main source #include "MyFirstClass.h" #include "MySecondClass.h" Make sure you use #ifdef around the header code so that it is only seen once.
22nd Feb 2018, 8:43 PM
John Wells
John Wells - avatar
+ 5
here is an example - something similar but, not quite. https://code.sololearn.com/c1d0hKINN7va/?ref=app
22nd Feb 2018, 7:12 PM
Manual
Manual - avatar
+ 5
Try In each .cpp include the .h file according to the class name create a main.h - include every .h in main.h - include main.h in main. cpp
22nd Feb 2018, 7:23 PM
Manual
Manual - avatar
+ 1
it worked.. well.. thanks.. you'd the best.. thank you all
23rd Feb 2018, 3:58 PM
Otumian Empire
Otumian Empire - avatar