is there anything wrong with this code in c++?
enum OpenMode{
Read = 0x1,
Write = 0x2,
Append = 0x4
};
void main(){
open_file("./something", OpenMode::Write); //!!!!!!!!!
}
void open_file(string name, OpenMode om){
.
.
.
}
All i need to do is to pass an enum to function without creating an instance of it.
Ok, Have you ever noticed the way ios works? For example:
somefile.open(file_name, ios::in | ios::out)
I need a way to do something like this: “something::something”!
Yes, there’s something wrong. The names created by a
enumgo into the scope that contains theenum, they are not qualified by theenum‘s name.In C++0x, there’s a new “enum class” syntax that nests the names within the enum.
A workaround in C++03 is to use a struct or namespace, i.e.:
Unfortunately it also changes the type name to
OpenMode::OpenMode.