我有一个带有一些 double 类型字段的 SQLite 数据库,我必须提取这个值并将它们放在一个实例变量中,但是我得到了这个错误
Assigning to 'double *' from incompatible type 'double'
这是代码:
数据库表.h
@interface DatabaseTable : NSObject {
sqlite3 * database;
}
//........
@property (nonatomic, assign)double *latitude; //latitude is a field of type double
@property (nonatomic, assign)double *longitude; //longitude is a field of a type double
@end
数据库表.m
//.....
while (sqlite3_step(statement) == SQLITE_ROW) {
DatabaseTable * rowTable =[[ChinaDatabaseTable alloc]init];
//.......
rowTable.latitude =sqlite3_column_double(statement, 15); //here the error
rowTable.longitude =sqlite3_column_double(statement, 16);//here the error
//.....
}
我能做什么?
最佳答案
您不需要在 int、float、bool 等原始类型之前放置 *
。
所以把代码改成这样:
@property (nonatomic, assign)double latitude; //latitude is a field of type double
@property (nonatomic, assign)double longitude; //longitude is a field of a type double
如果您需要创建一个指针变量,那么您的代码就可以了。
但是您不能将值直接分配给基本类型的指针值。
如果你需要分配地址值,你需要这样做:
double temp = sqlite3_column_double(statement, 15);
rowTable.latitude = &temp;
关于ios - 从不兼容类型 'double*' 分配给 'double',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13228230/