At the line 10: [warning] 'typedef' was ignored in this declaration [enabled by default].
Why is the typedef ignored???
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include<stdio.h>
typedefenum giorni{
Lunedi,
Martedi,
Mercoledi,
Giovedi,
Venerdi,
Sabato,
Domenica
};
int n;
giorni g;
int main(){
printf("Inserisci un numero da 1 a 7: ");
scanf("%d",&n);
g=giorni(n);
printf("\nGiorno corrispondente: %d",g);
}
At the line 10: [warning] 'typedef' was ignored in this declaration [enabled by default].
Why is the typedef ignored???
Are you compiling this as C or C++?
If you are compiling this as a C++ program remove the typedef from the front of your enum declaration. The warning is you received is not an error, the code compiles properly as C++.
I removed the typedef but it didn't go, so i tried to modify something but at the line 15 it says: 'giorni_settimana' cannot be used as a function
#include<stdio.h>
enum giorni{
Lunedi,
Martedi,
Mercoledi,
Giovedi,
Venerdi,
Sabato,
Domenica
}giorni_settimana;
int n,g;
int main(){
printf("Inserisci un numero da 1 a 7: ");
scanf("%d",&n);
g=giorni_settimana(n);
printf("\nGiorno corrispondente: %d",g);
}
In your first code example remove the typedef from before the enum and compile as C++. The warning is simply a warning that with C++ putting typedef before enum is not required. typedefenum is C code, enum by itself is C++ code.
Why are you trying to call your enum instance as if it were a function?
It did not look like a regular function call, when there was a typedef.
1 2 3 4 5
typedef T foo; // foo is a type. Same as T.
foo obj1 = foo( 42 ); // typecast by calling T's constructor that can accept int
T bar; // bar is an object
T obj2 = bar( 42 ); // bar is a "functor": T obj2 = bar.operator()( 42 );
The enums are names for constant values. Writing:
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#define foo 7
enum { bar = 3 };
constexprint gaz = 42;
int main() {
std::cout << foo << ' ' << bar << ' ' << gaz << '\n';
return 0;
}