EDIT: Thanks to you both!
I’m currently creating a template resource manager class and it doesn’t show any errors in the actual code, but when I compile i get hit with a few of these
error C2227: left of ‘->getHandle’ must point to class/struct/union/generic type
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;
}
For each resource i’ve got a base class Resource which looks like
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;
};
and i’m deriving various resources from this which i use like…
// just an abbreviated example
class Model : public Resource
{ };
ResourceManager<Model*> modelResourceManager;
modelResourceManager.add("model.obj", "models/");
Is there something i’m missing here? I’ve included “Resource.h” in ResourceManager.h and i’ve even included the specific implementations eg “model.h” but i’m still getting this error.
It could be very trivial, and i’ve just been staring at this entirely too long but help would be greatly appreciated.
You’re instantiating
modelResourceManagerwith the template argument set toModel*. That is,Twill beModel*in your templated code, soresourceandnewResource(which areT*) will beModel**– that is, pointer-to-pointer-to-Model.So
resource->isn’t valid.(*resource)->would be; or perhaps you meant to useModelas the template argument.