Compile error from Enumerated data type



  • I started writing a program in dev-C++ for a game and tried to move my work over to qt creator using microsoft visual's compiler(qt didn't like dev's GCC). When I copied everything over I got compile errors saying qt doesn't recognize my enumerated data type as a type.

    In data.h:
    @enum StatType {Health, Armor, Mana, HealthRegeneration, ManaRegeneration, AttackDamage,
    AbilityPower, LifeSteal, SpellVamp, MovementSpeed, AttackSpeed,
    CooldownReduction, MagicResist, MagicPenetration, ArmorPenetration,
    MovementSpeedPercent, CriticalDamage, CriticalChance, Gold, Experience,
    TimeDead, Energy, EnergyRegeneration, PercentHealth, None};
    @

    In glyph.h:
    @
    #include <QString>
    #include "data.h"

    using namespace std;

    class Glyph
    {
    public:
    QString name;
    double statAmount;
    StatType stat;
    bool isStatic;
    int costIP;

    double bonusAtLevel(int level);
    
    Glyph();
    

    };
    @

    The exact errors:
    e:\shared\stuff to save\gaming\lol\champion builder\qt\lol_champion_builder\glyph.h:20: error: C2146: syntax error : missing ';' before identifier 'stat'
    e:\shared\stuff to save\gaming\lol\champion builder\qt\lol_champion_builder\glyph.h:20: error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    e:\shared\stuff to save\gaming\lol\champion builder\qt\lol_champion_builder\glyph.h:20: error: C2208: 'stat' : no members defined using this type

    edit: I believe I've solved the problem - I had the enum declaration below the include statements.



  • The StatType you defined is a "local defined enum" and not a type. So in the class definition you can't generate a variable of that type!! Use typedef enum instead or place the enum in the class definition.
    Greetz



  • alternatively, I think you may use "enum StatType" instead of "StatType" alone when you instantiate the variable


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.