0
我不斷地收到這個錯誤,這讓我瘋狂!編譯C++時體系結構x86_64的未定義符號
Undefined symbols for architecture x86_64:
"SSResourcesDepot::_sharedInstance", referenced from:
SSResourcesDepot::sharedInstance() in SSResourcesDepot.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我的代碼如下所示:
#ifndef SolarSystem_SSResourcesDepot_h
#define SolarSystem_SSResourcesDepot_h
#include "SSResource.h"
/* SSResourcesDepot is implemented as a Singleton Depot that keeps track of all
* requested Resource objects, and avoid loading them twice in memory. */
class SSResourcesDepot {
SSResourcesDepot() {};
SSResourcesDepot(SSResourcesDepot const&){};
SSResourcesDepot& operator=(SSResourcesDepot const&){};
static SSResourcesDepot* _sharedInstance;
SSResource* _search(std::string resourceName);
SSResource* _load(std::string resourceName);
public:
static SSResourcesDepot* sharedInstance();
SSResource* requestResource(std::string resourceName);
};
#endif
和:
#include <iostream>
#include "SSResourcesDepot.h"
#pragma mark Public methods
SSResourcesDepot* SSResourcesDepot::sharedInstance() {
if (SSResourcesDepot::_sharedInstance == 0) {
SSResourcesDepot::_sharedInstance = new SSResourcesDepot();
}
return SSResourcesDepot::_sharedInstance;
}
SSResource* SSResourcesDepot::requestResource(std::string resourceName) {
SSResource *resource = this->_search(resourceName);
if (resource == NULL) resource = this->_load(resourceName);
return resource;
}
#pragma mark Private methods
SSResource* SSResourcesDepot::_search(std::string resourceName) {
return NULL;
}
SSResource* SSResourcesDepot::_load(std::string resourceName) {
return NULL;
}
似乎完全的功能給我,但蘋果-O-匹配器不斷抱怨,它不會讓我編譯...:-S
在此先感謝!
thaks,它的工作......只是一個小小的調整:'SSResourcesDepot * SSResourcesDepot :: _ sharedInstance = NULL;'(命名空間是在錯誤的地方!) –
@VicençGascó噢,當然,複製粘貼錯誤。編輯 –