Reputation: 51
I have a Class and this code inside:
public:
static enum AnimalTypes {Mammals, Fish, Birds, Horse, MammalsFish, Flamingo, GoldFish, Mermaid};
but then i get this warning :
Warning C4091 'static ': `ignored on left of 'const Zoo::AnimalTypes' when no variable is declared Line 269`
what cause this problem?
Upvotes: 0
Views: 756
Reputation: 1426
As I can see from your comments you are trying to declare a enumeration type AnimalTypes
which can be used all the classes in your code.
For a globel enmu use as follows in a header file.
#ifndef HEADER_H
#define HEADER_H
enum AnimalTypes {Mammals, Fish, Birds, Horse, MammalsFish, Flamingo, GoldFish, Mermaid};
this can be access from any of your class,
AnimalTypes at = Mammals;
But if you declare your enum inside the class, accessing style is bit different.
class Base
{
public:
enum AnimalTypes {Mammals, Fish, Birds, Horse, MammalsFish, Flamingo, GoldFish, Mermaid};
...
};
access style,
Base::AnimalTypes bat = Base::Mammals;
You should not use static
to declare a enumeration type. But you can use it to declare class variable.
Upvotes: 1
Reputation: 19445
static - mean a class variable, rather than an instance variable.
const - mean a none mutable (a non-changeable) variable.
both not relevant for enum definition. enum is not a variable.
so it should be:
public:
enum AnimalTypes {Mammals, Fish, Birds, Horse, MammalsFish, Flamingo, GoldFish, Mermaid};
Upvotes: 1
Reputation: 41474
You've got static const
there which suggests that you're trying to declare a class member variable, but then you've also got enum AnimalTypes {...}
which suggests you're trying to declare an enumeration type.
If you're trying to do the first thing (you're probably not), then put the variable name between the closing brace and the semicolon. If you're trying to declare an enumeration type, you should not have static const
. Those keywords apply to variables, not to type declarations.
Upvotes: 0