error: expected class-name before ‘{’ token

前端 未结 5 695
独厮守ぢ
独厮守ぢ 2020-11-30 05:41

I know there are a couple of similar questions(circular include) out stackoverflow and other websites. But I still can\'t figure it out and no solutions pop out. So I would

5条回答
  •  抹茶落季
    2020-11-30 06:12

    This should be a comment, but comments don't allow multi-line code.

    Here's what's happening:

    in Event.cpp

    #include "Event.h"
    

    preprocessor starts processing Event.h

    #ifndef EVENT_H_
    

    it isn't defined yet, so keep going

    #define EVENT_H_
    #include "common.h"
    

    common.h gets processed ok

    #include "Item.h"
    

    Item.h gets processed ok

    #include "Flight.h"
    

    Flight.h gets processed ok

    #include "Landing.h"
    

    preprocessor starts processing Landing.h

    #ifndef LANDING_H_
    

    not defined yet, keep going

    #define LANDING_H_
    
    #include "Event.h"
    

    preprocessor starts processing Event.h

    #ifndef EVENT_H_
    

    This IS defined already, the whole rest of the file gets skipped. Continuing with Landing.h

    class Landing: public Event {
    

    The preprocessor doesn't care about this, but the compiler goes "WTH is Event? I haven't heard about Event yet."

提交回复
热议问题