C++ class redefinition error - Help me understand headers and linking

后端 未结 3 475
梦毁少年i
梦毁少年i 2021-01-12 13:54

I started writing a simple interpreter in C++ with a class structure that I will describe below, but I quit and rewrote the thing in Java because headers were giving me a ha

3条回答
  •  有刺的猬
    2021-01-12 14:18

    Most header files should be wrapped in an include guard:

    #ifndef MY_UNIQUE_INCLUDE_NAME_H
    #define MY_UNIQUE_INCLUDE_NAME_H
    
    // All content here.
    
    #endif
    

    This way, the compiler will only see the header's contents once per translation unit.

提交回复
热议问题