Odd duplicate symbols error

后端 未结 1 817
失恋的感觉
失恋的感觉 2021-01-13 13:43

For a school project, the class was asked to write a String class to mimic the STL string class.

I have all the code written, but the linke

相关标签:
1条回答
  • 2021-01-13 14:30

    You provided the definitions of the operators in the header file which gets included by both String.cpp and test2.cpp.
    You should move the definitions into one source file and only provide declarations in the header file.

    // in String.h:
    bool operator==(const String& left, const char* right);
    
    // in String.cpp:
    bool operator ==(const String& left, const char* right) {
        return left.compare_to(right)==0; 
    }
    
    0 讨论(0)
提交回复
热议问题