在目标C中传递参考参数

时间:2013-03-05 06:36:53

标签: objective-c

我目前正在开发一个与sqlite数据库交互的项目。问题是每次我想连接数据库时,我都要打开并准备数据库。所以我想让这些步骤更加通用,我决定创建一个通用类,为我做这些步骤。

+(void)openAndPrepareDatabase:(sqlite3 *)db andStatement:(sqlite3_stmt *)statement andSql:(const char *)sql
{
@try
{
    if(!sqlite3_open([[self getDatabasePath] UTF8String], &db) == SQLITE_OK)
    {
        NSException *myException = [NSException exceptionWithName:@"Can't open database" reason:@"Can't open database" userInfo:Nil];

        @throw myException;
    }

    if(!sqlite3_prepare(db, sql, -1, &statement, NULL) == SQLITE_OK)
    {
        NSException *myException = [NSException exceptionWithName:@"Can't prepare database" reason:@"Can't prepare database" userInfo:Nil];

        @throw myException;
    }
}
@catch (NSException *exception)
{
    @throw exception;
}
}


+(void)openAndPrepareDatabaseV2:(sqlite3 *)db andStatement:(sqlite3_stmt *)statement andSql:(const char *)sql
{
@try
{
    if(!sqlite3_open([[self getDatabasePath] UTF8String], &db) == SQLITE_OK)
    {
        NSException *myException = [NSException exceptionWithName:@"Can't open database" reason:@"Can't open database" userInfo:Nil];

        @throw myException;
    }

    if(!sqlite3_prepare_v2(db, sql, -1, &statement, NULL) == SQLITE_OK)
    {
        NSException *myException = [NSException exceptionWithName:@"Can't prepare database" reason:@"Can't prepare database" userInfo:Nil];

        @throw myException;
    }
}
@catch (NSException *exception)
{
    @throw exception;
}
}

但是当我试图在我的对象中调用它时,I.E:

[Common openAndPrepareDatabase:&db andStatement:&statement andSql:sql];

我收到了警告:

"Incompatible pointer types sending 'sqlite3_stmt **' (aka 'struct sqlite3_stmt **')  to parameter of type 'sqlite3_stmt *' (aka 'struct sqlite3_stmt *'); remove &"

有谁知道我的问题的解决方案?

1 个答案:

答案 0 :(得分:1)

  

有谁知道我的问题的解决方案?

编译器 只显示了一个。

  

“不兼容的指针......等等; 删除&

(强调我的)