我有一个名为 Streamer 的课程。这是 Streamer.h
class Streamer {
public:
Streamer(const MyDb& realtimeDb);
virtual ~Streamer(void);
private:
virtual void callback_1(T_UPDATE pUpdate);
virtual void callback_2(Q_UPDATE pUpdate);
};
这是 Streamer.cpp
Streamer::Streamer(const MyDb& realtimeDb) {
}
Streamer::~Streamer(void) {
}
void Streamer::callback_1(T_UPDATE pUpdate) {
// I need to do something with pUpdate and realtimeDb here, like this:
// Getting a cursor from db (works fine in main.cpp, but not in callback)
Dbc *cursorp;
realtimeDb.getDb().cursor(NULL, &cursorp, 0);
}
void Streamer::callback_2(Q_UPDATE pUpdate) {
// I need to do something with pUpdate and realtimeDb here, like this:
// Getting a cursor from db (works fine in main.cpp, but not in callback)
Dbc *cursorp;
realtimeDb.getDb().cursor(NULL, &cursorp, 0);
}
Streamer 有两种方法,它们是来自 API 的回调。我无法更改这些参数。但是,我确实需要访问我传递给构造函数的数据库实例 MyDb(我什至这样做对吗?)。这就是我从 main.cpp 传递它的方式:
MyDb realtimeDb(databasePath, databaseName);
Streamer streamer(realtimeDb);
当我尝试从其中一个回调访问 realtimeDb 时,我得到:
error: 'realtimeDb' was not declared in this scope
有任何想法吗?谢谢!