来源MaxSumOfSubArray.cpp
:
#include <iostream>
namespace MaxSumOfSubArray {
void run() {
std::cout << "hey hey";
}
}
来源main.cpp
:
#include "MaxSumOfSubArray.cpp"
int main(int argc, const char * argv[])
{
MaxSumOfSubArray::run();
return 0;
}
但我得到了错误:
duplicate symbol __ZN16MaxSumOfSubArray3runEv in:
/Users/li.tonghui/Library/Developer/Xcode/DerivedData/CppChallenges-eobfuxlkqjfgebendxkoqbsvsbmr/Build/Intermediates/CppChallenges.build/Debug/CppChallenges.build/Objects-normal/x86_64/main.o
/Users/li.tonghui/Library/Developer/Xcode/DerivedData/CppChallenges-eobfuxlkqjfgebendxkoqbsvsbmr/Build/Intermediates/CppChallenges.build/Debug/CppChallenges.build/Objects-normal/x86_64/MaxSumOfSubArray.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
为什么我会收到此错误以及如何解决?