I have an issue that I am hoping someone can help me with. I want to override the new and delete operators so I can keep track of all memory allocations in a MemoryManager class. The issue I am having is as follows.
All of my managers inherit from a Singleton class to guarantee that only one instance of each exists.
Here is my definition of a class ResourceManager
#pragma once
#include "../SosaGlobal.h"
class ResourceManager : public Singleton <ResourceManager>
{
public:
ResourceManager(void);
~ResourceManager(void);
};
Next in my application class, I am trying to declare an instance of the ResourceManager as follows.
In my header file app.h
#include "Resource/ResourceManager.h"
ResourceManager resourceManager;
and in my app.cpp file
resourceManager = new ResourceManager();
I get the following error:
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'ResourceManager *' (or there is no acceptable conversion)
If I remove this line from the header file
ResourceManager resourceManager;
and in the app.cpp I call
ResourceManager resourceManager = new ResourceManager();
Then I get a different error:
error C2440: 'initializing' : cannot convert from 'ResourceManager *' to 'ResourceManager'
FYI, if I do the following I can declare an instance but not using the new operator.
for example:
AudioManager audioManager;
audioManager.Initialize();
Can someone please let me know why I get use the new operator to declare an instance of my class?
All of my managers inherit from a Singleton class to guarantee that only one instance of each exists.
Here is my definition of a class ResourceManager
#pragma once
#include "../SosaGlobal.h"
class ResourceManager : public Singleton <ResourceManager>
{
public:
ResourceManager(void);
~ResourceManager(void);
};
Next in my application class, I am trying to declare an instance of the ResourceManager as follows.
In my header file app.h
#include "Resource/ResourceManager.h"
ResourceManager resourceManager;
and in my app.cpp file
resourceManager = new ResourceManager();
I get the following error:
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'ResourceManager *' (or there is no acceptable conversion)
If I remove this line from the header file
ResourceManager resourceManager;
and in the app.cpp I call
ResourceManager resourceManager = new ResourceManager();
Then I get a different error:
error C2440: 'initializing' : cannot convert from 'ResourceManager *' to 'ResourceManager'
FYI, if I do the following I can declare an instance but not using the new operator.
for example:
AudioManager audioManager;
audioManager.Initialize();
Can someone please let me know why I get use the new operator to declare an instance of my class?