3

在 sqlite3_open 函数(通用 C 函数)中,我需要将 sqlite3 通用 C 指针的地址作为参数发送。
例子:

//Valid code
NSString * databaseFile; //Path of database file. (Objective-C Object)
sqlite3 * db; //Pointer to hold the sqlite database. (C Pointer)

sqlite3_open([databaseFile UTF8String], &db); //db is sent using the & operator.

问题是我需要从对象内部获取 *db 变量。我知道这段代码是错误的,但它是一种解释我需要什么的方法:

//I need to get the address of the pointer 'database' from inside the Objective-C Object 'object'.
//I hope one of those wrong lines explain what I want:

sqlite3_open([databaseFile UTF8String], &[object database]);
sqlite3_open([databaseFile UTF8String], [object &database]);
sqlite3_open([databaseFile UTF8String], &(object->database);

我希望有人能理解我......哈哈哈谢谢你的时间!=)

4

1 回答 1

1

假设MyClass看起来像这样:

@interface MyClass : NSObject
...
@property ( nonatomic ) sqlite3 * database ;
...
@end

您的代码将是:

MyClass * object = ... ;

sqlite3 * database ;
sqlite3_open( ..., & database ) ;

object.database = database ;
于 2012-10-25T01:50:24.190 回答