可能重复:
What are the differences between struct and class in C++
class and struct in c++C++结构OO VS类OO
它看起来像结构可以有构造函数和析构函数和成员,而且看起来很简单,所以可以我们使用struct而不是class,如果不是的话,我们什么时候应该使用结构和函数?
https://github.com/developmentseed/node-sqlite3/blob/master/src/database.h#L32
struct Baton {
uv_work_t request;
Database* db;
Persistent<Function> callback;
int status;
std::string message;
Baton(Database* db_, Handle<Function> cb_) :
db(db_), status(SQLITE_OK) {
db->Ref();
uv_ref(uv_default_loop());
request.data = this;
callback = Persistent<Function>::New(cb_);
}
virtual ~Baton() {
db->Unref();
uv_unref(uv_default_loop());
callback.Dispose();
}
};
struct OpenBaton : Baton {
std::string filename;
int mode;
OpenBaton(Database* db_, Handle<Function> cb_, const char* filename_, int mode_) :
Baton(db_, cb_), filename(filename_), mode(mode_) {}
};
范围是一样的。访问级别不是。 – 2011-12-22 12:14:40
感谢您指出了这一点;我已经修改了我的答案 – BigDaveDev 2011-12-23 06:46:50