duplicate symbol error C++

后端 未结 4 2111
感情败类
感情败类 2020-11-29 06:35

I have added some const character in my file as under. The error i get is duplicate symbol _xyz(say). What is the problem with it and how could i get out of this.



        
4条回答
  •  天命终不由人
    2020-11-29 07:04

    The problem is every source file that includes your header file gets it's own copy of xyz with external linkage.

    The easiest way to fix that is to give xyz internal linkage. You can do that by making the pointer itself const in addition to having the underlying char's const:

    const char* const xyz = "xyz";
    

提交回复
热议问题