C\C++区别 枚举类型enum

2014-06-14  本文已影响314人  Amrzs

C\C++区别 枚举类型enum

from my csdn blog

enum.c

#include <stdio.h>

enum ShapeType{
    circle = 10, square = 20, rectangle = 30
};

int main(){

    enum ShapeType shape = circle;
    shape++;
    printf("%d\n", shape);

    return 0;
}
amrzs@ubuntu:cc$ gcc enum.c
amrzs@ubuntu:cc$ ./a.out 
11

enum.cpp

#include <cstdio>
using namespace std;

enum ShapeType{
    circle = 10, square = 20, rectangle = 30
};

int main(){

    ShapeType shape = circle;
    shape++;
    printf("%d\n", shape);

    return 0;
}
amrzs@ubuntu:cc$ g++ enum.cpp 
enum.cpp: In function ‘int main()’:
enum.cpp:11:10: error: no ‘operator++(int)’ declared for postfix ‘++’ [-fpermissive]
     shape++;

分析

上一篇下一篇

猜你喜欢

热点阅读