+ 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 {
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.
+ 5
here is an example
- something similar but, not quite.
https://code.sololearn.com/c1d0hKINN7va/?ref=app
+ 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
+ 1
it worked.. well.. thanks.. you'd the best.. thank you all