我不断收到这个错误,这让我发疯!
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;
}
它对我来说似乎完全正常,但 Apple-O-Matcher 一直在抱怨,而且它不允许我编译...... :-S
提前致谢!