[英]Cannot convert from '_int64' to 'Data *'
In my project i have a class to work with time, it's declared like this: 在我的项目中,我有一个与时间相关的类,它的声明如下:
class Data {
int dia;
int mes;
int ano;
int hora;
int minuto;
public:
Data();
Data(int, int, int, int, int);
Data(const Data &);
void mostraData();
void ImprimeData();
Data operator-(const Data &aux);
};
dia = day, mes = month, ano = year, hora = hour.... (portuguese) dia =天,mes =月,ano =年,hora =小时....(葡萄牙语)
And at certain point i have to calculate the difference between two differente times. 在某些时候,我必须计算两个不同时间之间的差。 So i made this simple operator -:
所以我做了这个简单的运算符-:
Data Data::operator-(const Data & aux){
Data temp(0, 0, 0, 0, 0);
temp.dia = this->dia - aux.dia;
temp.mes = this->mes - aux.mes;
temp.ano = this->ano - aux.ano;
temp.hora = this->hora - aux.hora;
temp.minuto = this->minuto - aux.minuto;
return temp;
}
Now, I was just testing to see if it calculates the right time, I wrote this peace of code: 现在,我正在测试以查看它是否计算出正确的时间,我编写了以下代码:
aux = new Data;
Data *teste = new Data(7, 7, 2016, 22, 41);
Data * resultado = teste - aux;
resultado->ImprimeData();
Ps. 附言 the function "ImprimeData()" is to print the result.
函数“ ImprimeData()”将打印结果。 But on the third line it gives me an error.
但是在第三行,它给了我一个错误。 First it says that a value of tipo 'long long' cannot be used to initialize an entety of type 'Data *', and then it says that cannot convert from _int64 to Data *.
首先,它说tipo'long long'的值不能用于初始化类型为'Data *'的实体,然后它说不能将_int64转换为Data *。
This line 这条线
Data * resultado = teste - aux;
should be 应该
Data resultado = *teste - *aux;
The first is subtracting two pointer values. 首先是减去两个指针值。 The second is calling your
operator -
overload. 第二个是打电话给您的
operator -
重载。
You should also change 你也应该改变
resultado->ImprimeData();
to 至
resultado.ImprimeData();
Your teste is a pointer, as is your aux. 您的睾丸和辅助都是指针。
Which is a bit off since my testes would be considered more a container and/or factory. 这有点离谱,因为我的睾丸被更多地视为一个容器和/或工厂。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.