C++:错误 C2675:一元"++"
C++ : error C2675: unary '++'
我使用C 时有一个C2675错误。
#include<stdio.h>
int main(void){
enum months {jan=1, feb, mar, apr, jun, aug, sep, oct, nov, dec};
enum TV { kbs1 =9, kbs2 = 7, mbc =11, sbs = 6};
enum months mon;
printf("kbs1 : %d",kbs1);
printf("kbs2 : %d",kbs2);
printf("mbc : %d", mbc);
printf("sbs : %d", sbs);
for(mon = jan; mon<=dec; ++mon){
printf("%d",mon);}
return 0;
但是,有结果...
error C2675: unary '++' : 'main::months' does not define this operator or a conversion to a type acceptable to the predefined operator.
请帮助我如何解决此问题... T_T
一个(丑)解决方案是:
for( mon = jan; mon <= dec; mon = (months)(mon + 1) )
{
printf("%d", mon);
}
,但它仅是因为您的枚举值是连续的,并且与您的TV enum
无法使用。
相关文章:
- 一元*运算符的操作数是否期望一个 prvalue
- 一元"运算符"未在C++中定义
- 如何解决一元"*"(有"字符")错误的无效类型参数?
- C++11 标准是否保证零值有符号整数的一元减号为零?
- 应用于无符号类型的一元减号运算符
- C2675 一元运算符由错误的作用域引起
- 如何在 std::transform 中使用 std::p ow 作为一元函数?
- 如何解决参数为一元的错误?
- 你能帮我了解重载一元运算符和二进制运算符之间的区别吗?
- 泛型lambda和一元+运算符
- 为什么'auto'不尊重一元减号运算符?
- 在C++中,一元减号运算符如何处理整数文本
- 位集构造函数中的一元按位或折叠
- 错误:一元"*"的类型参数无效(具有"int"):使用 mergesort 计算
- 创建指针是否超过非数组指针的末尾,而不是从 C++17 中的一元运算符和未定义的行为派生?
- 错误 带有模块的一元"*"(具有"int")的类型参数无效
- 为什么我不能定义一元运算符,然后在 MSVC 的模板类中声明具有相同名称的友元二进制运算符?
- 替换包含已弃用的一元函数的自定义模板
- C++一元右折与一元左折,带逗号运算符
- C++:错误 C2675:一元"++"