从不兼容的类型'double'分配'double *'

时间:2012-11-05 08:14:53

标签: ios database sqlite double

我有一个SQLite数据库,其中包含一些double类型的字段,我必须提取这个值并将它们放在一个实例变量中,但是我得到了这个错误

  Assigning to 'double *' from incompatible type 'double'

这是代码:

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

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

           //.....
     }

我该怎么办?

1 个答案:

答案 0 :(得分: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

如果你需要创建一个指针变量,那么你的代码就可以了。

但是你不能将值直接赋值给基元类型的指针值。

如果您需要分配地址值,则需要执行以下操作:

double temp = sqlite3_column_double(statement, 15);
rowTable.latitude = &temp;