我有一个SQLite数据库,其中包含一些double类型的字段,我必须提取这个值并将它们放在一个实例变量中,但是我得到了这个错误
Assigning to 'double *' from incompatible type 'double'
Run Code Online (Sandbox Code Playgroud)
这是代码:
DatabaseTable.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
Run Code Online (Sandbox Code Playgroud)
DatabaseTable.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
//.....
}
Run Code Online (Sandbox Code Playgroud)
我能做什么?
Mid*_* MP 10
你不需要*在诸如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
Run Code Online (Sandbox Code Playgroud)
如果你需要创建一个指针变量,那么你的代码就可以了.
但是,您无法直接将值分配给基元类型的指针值.
如果需要分配地址值,则需要执行以下操作:
double temp = sqlite3_column_double(statement, 15);
rowTable.latitude = &temp;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5933 次 |
| 最近记录: |