私はCを新しく読んでいます。「Cの簡単なステップでのプログラミング」という本の中の概念とサンプルコードを読んでいます。intからmain():: colorsへの無効な変換ですか?
だから、私はこのプログラム例、文字の文字を入力:
#include <stdio.h>
int main()
{
/* declare a sequence of constants */
enum colors
{ RED=1,YELLOW,GREEN,BROWN,BLUE,PINK,BLACK };
/* Declare a variable of the enumerated data type */
enum colors fingers;
/* assign valid constants from the colors list */
/* -----THIS IS THE ERROR LINE BELOW---------- */
fingers = (enum colors) PINK + BROWN;
/*-display the value in the variable */
printf("Value: %d\n", fingers);
return 0;
}
と私はこのエラーを取得:コンパイラはfingers
を認識しないいくつかの理由について
13 C:\Users\mjohearn\Documents\pet projects\constant types NOT WORKING\enumtypes.cpp invalid conversion from `int' to `main()::colors'
を。
誰でも私がこの問題を解決するのを手伝ってくれたら、本当にありがとう。
ああ、私は答えの潮を受け取ることができます... – Ulterior
Cのファイル拡張子は ".c"です。 ".cpp"はC++用です。 (また、Cコンパイラではなく、Cコンパイラを使用してC言語をコンパイルすることもできます)。 – geoffspear
あなたのリストから外れるPINK + BROWN = 10。さらに、PINK + BROWNを型キャストする必要がありますか? –