Having trouble with class scope

Hello,

Long time programmer, first time C++.

I have a class called Streamer. Here is Streamer.h:

1
2
3
4
5
6
7
8
9
10
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);
};


Here is Streamer.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 has two methods that are callbacks from an API. I can't change these parameters. I do, however, need to access the database instance MyDb that I am passing to the constructor (am I even doing that right?). This is how I am passing it, from main.cpp:


1
2
MyDb realtimeDb(databasePath, databaseName);
Streamer streamer(realtimeDb);


When I try to access realtimeDb from one of the callbacks, I get:

error: 'realtimeDb' was not declared in this scope

Any ideas? Thanks!
Last edited on
I don't think you need to declare a destructor as virtual, I believe that's implied.
You did not show how you call your callback class member functions and how they access a database instance.
Oh, sorry. Edited to include Streamer.cpp. Thanks.
Again you did not show how you call your callback class members and how they access a database instance.
Accessing the database instance from the callback is the part I'm not sure about :P

I can access it fine from main.cpp. Updated with the code I have.

I'm not sure exactly where the callback is being called from, it's in an external library.
In this case why do you pass reference to a database instance to your constroctor?
The callbacks are being called 300,000 times per second. I don't want to open a new database connection each time. I want to use the same database instance.

I think I need some kind of class property in Streamer that holds the instance, and allows it to be accessed from the callback methods.
Topic archived. No new replies allowed.