One or more multiply defined symbols found

后端 未结 9 642
夕颜
夕颜 2020-11-30 04:38

DebugUtil.h

#ifndef DEBUG_UTIL_H
#define DEBUG_UTIL_H

#include 

int DebugMessage(const char* message)
{
    const int MAX_CHARS = 1023;
           


        
9条回答
  •  情书的邮戳
    2020-11-30 04:56

    (Assuming the posted code is a header, included from multiple .cpp files)

    Header guards do not protect you from link-time multiple definitions. Regardless that you have ensured the header will only appear once per Translation Unit, if you have more than one Translation Unit then that's still multiple definitions.

    Write definitions in source files, and only declarations in headers.

    The only exceptions are inline functions, functions defined within a class definition (though this is not recommended!) and function templates.

提交回复
热议问题