Check if string
and shared_ptr
are declared, and try specifying namespaces for them (replace shared_ptr
with boost::shared_ptr
or std::shared_ptr
) to make sure that the same class is used in declaration and implementation of ToString
.
redefinition of 'WhatEver' as different kind of symbol [duplicate]
-
12-10-2022 - |
Question
I'm trying to migrate some legacy code into a newer project and I don't really get this one fixed. The code compiled and worked well in the older environment.
I have a header file which contains these definitions:
std::string ToString(shared_ptr<const SomeObject> obj);
std::string ToString(SomeObject* obj);
And an implementation file with following lines:
using namespace std;
string ToString(shared_ptr<const SomeObject> obj)
{
// code cut
return outstring.str();
}
string ToString(SomeObject* obj)
{
// code cut
return outstring.str();
}
I'm trying to compile it with clang
and I get the following redefinition error:
.../Filename.cxx:15:8: error: redefinition of 'ToString' as different
kind of symbol
string ToString(shared_ptr<const SomeObject> obj)
^
.../Filename.h:15:13: note: previous definition is here
std::string ToString(SomeObject* obj);
Why is it a redefinition as different kind of symbol? How should I fix this? And last but not least, why does it work with older compilers?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow