jakesee 0 Junior Poster

Hi,

I am trying to implement a Data Manager class (singleton) that initializes data, keep track of memory usage and acts as a data pool for other classes to share the data.

My problem lies with the sharing. After considering serveral factors, I want to share data in the form of function pointers from the Data Manager. But I failed to do so, perhaps due to the lack of knowledge in the type of function pointers (function call types).

Hope someone can give an advice how to go about doing this or suggest other methods:

#include <iostream>

using namespace std;

class Data
{
public:
	static Data& Manager()
	{
		static Data _data;
		return _data;
	}

	void init()
	{
		// initialize data
	}

	// data types
	void Data1()
	{
		cout << "some data 1" << endl;
	}
	void Data2()
	{
		cout << "some data 2" << endl;
	}
};


class VariableDataObject
{
private:
	void (*callback)(void);
public:
	VariableDataObject(void (*_dataCallback)(void))
	{	
		callback = _dataCallback;
	}

	void Output()
	{
		callback();
	}
};

int main()
{
	// create object and assign different data
	// xxx this part does work
	// xxx parameter type error
	// xxx How to fix?
	VariableDataObject o1(Data::Manager().Data1);
	VariableDataObject o2(Data::Manager().Data2);

	// output the data assigned
	o1.Output();
	o2.Output();

	return 0;
}