enum{
INT,
FLOAT,
STRING
}type;
int value;
}mystruct;
mystruct v1[2]={0,100,1,200}
这样编译后提示error C2440: 'initializing' : cannot convert from 'const int' to 'enum mytag
请问如何初始化?
7 个解决方案
#1
enum TYPE{
INT,
FLOAT,
STRING
};
typedef struct mytag{
TYPE type;
int value;
}mystruct;
mystruct v1[2]={INT,100,FLOAT,200}
INT,
FLOAT,
STRING
};
typedef struct mytag{
TYPE type;
int value;
}mystruct;
mystruct v1[2]={INT,100,FLOAT,200}
#2
enum Type{
INT,
FLOAT,
STRING
};
typedef struct mytag{
Type type;
int value;
}mystruct;
mystruct v1[2]={{INT,100},{FLOAT,200}};
INT,
FLOAT,
STRING
};
typedef struct mytag{
Type type;
int value;
}mystruct;
mystruct v1[2]={{INT,100},{FLOAT,200}};
#3
typedef struct mytag{
enum{
INT,
FLOAT,
STRING
}type;
int value;
}mystruct;
mystruct v1[2]={mytag::INT,100,mytag::FLOAT,200};
enum{
INT,
FLOAT,
STRING
}type;
int value;
}mystruct;
mystruct v1[2]={mytag::INT,100,mytag::FLOAT,200};
#4
必须指定域
#include<iostream>
using namespace std;
typedef struct mytag{
enum{
INT,
FLOAT,
STRING
}type;
int value;
}mystruct;
mystruct v1[2]={mytag::INT,100,mytag::FLOAT,200};
int main()
{
return 0;
}
#include<iostream>
using namespace std;
typedef struct mytag{
enum{
INT,
FLOAT,
STRING
}type;
int value;
}mystruct;
mystruct v1[2]={mytag::INT,100,mytag::FLOAT,200};
int main()
{
return 0;
}
#5
你用的是什么编译器?VC6下没问题
#6
我用的是vc6编译器
#7
谢谢各位
#1
enum TYPE{
INT,
FLOAT,
STRING
};
typedef struct mytag{
TYPE type;
int value;
}mystruct;
mystruct v1[2]={INT,100,FLOAT,200}
INT,
FLOAT,
STRING
};
typedef struct mytag{
TYPE type;
int value;
}mystruct;
mystruct v1[2]={INT,100,FLOAT,200}
#2
enum Type{
INT,
FLOAT,
STRING
};
typedef struct mytag{
Type type;
int value;
}mystruct;
mystruct v1[2]={{INT,100},{FLOAT,200}};
INT,
FLOAT,
STRING
};
typedef struct mytag{
Type type;
int value;
}mystruct;
mystruct v1[2]={{INT,100},{FLOAT,200}};
#3
typedef struct mytag{
enum{
INT,
FLOAT,
STRING
}type;
int value;
}mystruct;
mystruct v1[2]={mytag::INT,100,mytag::FLOAT,200};
enum{
INT,
FLOAT,
STRING
}type;
int value;
}mystruct;
mystruct v1[2]={mytag::INT,100,mytag::FLOAT,200};
#4
必须指定域
#include<iostream>
using namespace std;
typedef struct mytag{
enum{
INT,
FLOAT,
STRING
}type;
int value;
}mystruct;
mystruct v1[2]={mytag::INT,100,mytag::FLOAT,200};
int main()
{
return 0;
}
#include<iostream>
using namespace std;
typedef struct mytag{
enum{
INT,
FLOAT,
STRING
}type;
int value;
}mystruct;
mystruct v1[2]={mytag::INT,100,mytag::FLOAT,200};
int main()
{
return 0;
}
#5
你用的是什么编译器?VC6下没问题
#6
我用的是vc6编译器
#7
谢谢各位