Hi all,
I'm having trouble with the following:
foo.h#ifndef FOO_H
#define FOO_H
#include <string>
class Foo {
public:
typedef std::string StringType;
// ...
static const StringType default;
private:
// ...
};
#endif
foo.cpp#include "foo.h"
const Foo::StringType default = Foo::StringType();
main.cpp#include "foo.h"
int main()
{
Foo::StringType s = "foo";
if (s == Foo::default)
s = "bar";
}
Trying to compile this (on MSVC++ 2008 Express) gives the following linker errors:
1>main.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const Foo::default" (?st@Foo@@2V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B)
1>C:\Documents and Settings\d\Desktop\foo\Debug\foo.exe : fatal error LNK1120: 1 unresolved externals
I can't seem to figure out what the problem is; if anyone can help me out I'd greatly appreciate it.