I'm trying to iterate through an non-consecutive enumeration with a range-based loop. I took the approach from this answer to another question: https://stackoverflow.com/a/26910769/9477190
My header:
namespace Asset
{
enum Type
{
First = 0,
Second,
Third,
Fourth = 10,
Fifth,
Sixth
};
static const Type All[] = { First, Second, Third, Fourth, Fifth, Sixth };
}
Class Example
{
public:
Example();
~Example();
private:
void doSomething(Asset::Type asset);
void doSomethingElse();
};
My class definition:
Example::Example()
{
for(const auto asset : Asset::All)
{
// do something
doSomething(asset);
doSomethingElse();
}
}
My functions doSomething() and doSomethingElse() are never called or executed. I've tested my code and did various prints of Asset::All[2] and other indexes and it prints the desired value of the enumeration so why is the for-loop not working?
I've also tried not using auto as well and used const Asset::Type asset instead and I get the same results. My code compiles fine and I'm using the -std=c++11 compiler option.
Aucun commentaire:
Enregistrer un commentaire