#ifndef DATACENTER_H_
#define DATACENTER_H_
#include <map>
#include <list>
#include <string>
#include "LiLo/SoundInfo.h"
#include "MutexCondition.h"
#include "UserInfo.h"
using namespace std;
class DataCenter : MutexCondition{
private:
map<long long, list<SoundInfo *> > m_soundListMap;
void add(long long deviceId, SoundInfo* soundInfo);
public:
DataCenter();
virtual ~DataCenter();
static void addSoundInfo(long long deviceId, SoundInfo *soundInfo);
};
#endif /* DATACENTER_H_ */
DataCenter.cpp file
#include "DataCenter.h"
DataCenter::DataCenter() {
// TODO Auto-generated constructor stub
}
DataCenter::~DataCenter() {
// TODO Auto-generated destructor stub
}
void DataCenter::addSoundInfo(long long deviceId, SoundInfo *soundInfo){
add(deviceId, soundInfo);
}
void DataCenter::add(long long deviceId, SoundInfo *soundInfo){
list<SoundInfo*>& info_list = m_soundListMap[55];
}
I am trying to access the function call addSoundInfo from other classes so I have set this as static. Since the m_soundListMap is not a static so I think I need another function to access to the local data structure.
Inside of the static function, I call add function to add SoundInfo to the list. However, I am getting an error in the static function and it says “Can not call member function …. without object”.
How do I fix this problem? Thanks in advance..
If you want to access
addSoundInfofrom other classes, you need to make itpublic, or make those other classes friends ofDataCenter.statichas nothing to with access control.A static function is not bound to an instance of the class it belongs to, and thus can not access members of that class (it also can not call member-functions). If you really want to access members from a static function, you have to pass an instance of the class as argument the the static function explicitly.
If you struggle with such basic concepts, you should read a good book.