Я пытаюсь инициализировать статический член класса, и мне не повезло. Вот тест:
файл Test.h
#include <string>
class Test {
public:
static void init(char*);
private:
static std::string *sp;
};
файл Test.cpp
#include "Test.h"
// Initialize the class
void
Test::init(char *foo) {
Test::sp = new std::string(foo);
}
int main(int argc, char** argv) {
Test::init(argv[1]); // call the class initializer
}
Компоновщик терпит неудачу с:
Undefined symbols for architecture x86_64:
"Test::sp", referenced from:
Test::init(char*) in Test-OK13Ld.o
ld: symbol(s) not found for architecture x86_64
В реальном мире init() проделает реальную работу по установке статического члена. Может ли кто-нибудь указать на ошибку?
static std::string *sp;
не определено. - person user1810087   schedule 15.07.2013