我收到了一个转换错误,实际上并不知道如何解决它。C++转换错误:从短int *无效转换为short int
我必须使用这些结构,并且不知道如何访问Date结构权限。 这里是我的代码:从GCC
#include <iostream>
#include <string.h>
using namespace std;
struct Date {
short year;
short month;
short day;
};
struct Stuff {
Date birth;
};
struct ListElement {
struct Stuff* person; // Pointer to struct Stuff
struct ListElement* next; // Pointer to the next Element
};
int main() {
short birth_year;
short birth_month;
short birth_day;
cin >> birth_year;
cin >> birth_month;
cin >> birth_day;
ListElement* const start = new ListElement();
ListElement* actual = start;
actual->person = new Stuff();
actual->person->birth.year = new short[sizeof(birth_year)]; // Conversion Error
delete start;
delete actual;
}
错误消息:
main.cpp: In function 'int main()':
main.cpp:35:29: error: invalid conversion from 'short int*' to 'short int' [-fpermissive]
actual->person->birth.year = new short[sizeof(birth_year)]; // Conversion Error
错误信息在哪里? – Deduplicator
这段代码没有意义。你为什么试图将一个数组分配给一个'short'? –
[请详细阅读你的编译器告诉你的内容](http://ideone.com/poCJJk)!你的标题是错误的。你不需要'new()'在那里。 –