GCC compiler error: “redefinition…previously defined”

前端 未结 4 1859
再見小時候
再見小時候 2021-02-02 15:39

I\'m getting a lot of \" redefinition of x....x previously defined here\". Please what does this error means?

4条回答
  •  忘了有多久
    2021-02-02 16:23

    You need to limit each file from being included only once. You can do this in 2 ways.

    1) At the top of your header files put:

    #pragma once
    

    Or 2) if your compiler doesn't support that, put at the top/end of your header files:

    #ifndef _MYFILE_H_
    #define _MYFILE_H_
    ...
    #endif
    

    Replace MYFILE with the name of your file, and replace ... with the contents of the header file.

提交回复
热议问题