Possible Duplicate:
C++ static constant string (class member)
static const C++ class member initialized gives a duplicate symbol error when linking
My experience with C++ pre-dated the addition of the string class, so I’m starting over in some ways.
I’m defining my header file for my class and want to create a static constant for a url. I’m attempting this by doing as follows:
#include <string>
class MainController{
private:
static const std::string SOME_URL;
}
const std::string MainController::SOME_URL = "www.google.com";
But this give me a duplicate definition during link.
How can I accomplish this?
Move the
to a cpp file. If you have it in a header, then every .cpp that includes it will have a copy and you will get the duplicate symbol error during the link.