이 기능에 문제가 있습니다. 이 함수는 StoredData
유형을 반환합니다. 함수에서 void 사용. 인식하지 못함
이
내 구조체입니다 :struct StoredData
{
void* data;
int size;
int type;
int compareValue;
StoredData():
size(0),
type(0),
compareValue(0){}
};
그리고이 제 기능입니다 : 내가
*data = (bool)input2;
의 경우 문 내 라인에 문제가있어 불행하게도
StoredData SDI::Array::create(int size, int type, int compareValue)
{
StoredData temp;
void* data;
int input;
int input2;
std::cout<<"What type of data would you like to insert?"<<std::endl;
std::cout<<"1 - Integer"<<std::endl;
std::cout<<"2 - Boolean"<<std::endl;
std::cin>>input;
std::cout<<"What is the value?"<<std::endl;
std::cin>>input2;
switch (input)
{
case 1:
size = sizeof(int);
type = 0;
data = new int;
*data = (int)input2;
break;
case 2:
size = sizeof(bool);
type = 1;
data = new bool;
*data = (bool)input2;
break;
}
temp.compareValue=input2;
temp.data = data;
temp.type = type;
temp.size = size;
}
내가 얻는 오류는 완전한 개체 형식에 대한 포인터 여야한다는 것입니다. 데이터를 인식하려면 void
변수가 필요하며 운이 없다. 누구나 해결 방법을 알고 있습니까?
각각에 대해 2 개의 오류 메시지가 표시됩니다. , 첫 번째는
illegal indirection
이고 두 번째 사람은
error C2440: '=' : cannot convert from 'int' to 'void *'
error C2440: '=' : cannot convert from 'bool' to 'void *'
왜 '공용체'유형 대신에 '무효'유형을 사용하고 있습니까? 튀어 나오는 또 하나의 문제는 참조 할 '데이터'에 할당 된 메모리가 없다는 것입니다. – abiessu
void * 또는 union을 사용하지 마십시오. Boost :: variant를 사용하십시오. – Davidbrcz
@Davidbrcz이 질문에 태그가 추가 되었습니까? –