编辑:谢谢你们!
我目前正在创建一个模板资源管理器类,它在实际代码中没有显示任何错误,但是当我编译时,我遇到了其中一些
错误 C2227:“->getHandle”左侧必须指向类/结构/联合/通用类型
template <class T>
unsigned int ResourceManager<T>::add(string& name, string& path)
{
T* resource = getResource(name, path);
if (resource != nullptr)
{
resource->incrementCount(); // doesn't like
return resource->getHandle(); // these lines calling member functions
}
else
unsigned int handle;
bool freeHandle = false;
if (!m_freeHandles.empty())
{
handle = m_freeHandles.top();
m_freeHandles.pop();
freeHandle = true;
}
else
{
handle = m_resourceList.size();
freeHandle = false;
}
T* newResource = new T(handle, name, path);
if (!freeHandle)
m_resourceList.push_back(newResource);
else
m_resourceList[handle] = newResource;
return newResource->getHandle();
}
return -1;
}
对于每个资源,我都有一个基类 Resource ,它看起来像
class Resource
{
public:
Resource(unsigned int handle, string& name, string& path);
Resource(string& name, string& path);
virtual ~Resource();
string getFileName() { return m_filename; }
void setFileName(string filename) { m_filename = filename; }
string getFilePath() { return m_filepath; }
void getFilePath(string filePath) { m_filepath = filePath; }
string getName() { return m_name; }
void getName(string name) { m_name = name; }
unsigned int getHandle() { return m_handle; }
void setHandle(unsigned int handle) { m_handle = handle; }
void incrementCount() { m_referenceCount++; }
void decrementCount() { m_referenceCount--; }
int getReferenceCount() { return m_referenceCount; }
protected:
string m_filename;
string m_filepath;
string m_name;
unsigned int m_handle;
int m_referenceCount;
};
我正在从中获取各种资源,我使用这些资源......
// just an abbreviated example
class Model : public Resource
{ };
ResourceManager<Model*> modelResourceManager;
modelResourceManager.add("model.obj", "models/");
我在这里缺少什么吗?我在 ResourceManager.h 中包含了“Resource.h”,甚至包含了特定的实现,例如“model.h”,但我仍然收到此错误。
这可能是非常微不足道的,我一直盯着这个太久了,但我们将不胜感激。