Why isn't this call working properly?

I'm building a project for myself really; however, this problem is sticking me in the side. Can anyone tell me why this particular problem isn't working

#include "pl_en_stats.h" // in *.cpp file for icPlayerInformation_Data struct usage.

// in *.h file for Class definition.


class LoadGameData
{

private:
char PlayerInformation;
icPlayerInformation_Data* pl_statistics;

public:
LoadGameData();
bool load_SaveData_Open();
void load_SaveData_Variables( icPlayerInformation_Data &pl_Statistics );
bool load_SaveData_Close();
~LoadGameData();

};

==PathRemoved==(24) : error C2143: syntax error : missing ';' before '*'

==PathRemoved==(24) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Main.cpp(33) : error C3861: 'load_SaveData_Open': identifier not found

icPlayerInformation_Data is typedef struct { enum { }; variables }; and named as such.

Let me know if you would like more information:

Platform: WINxp
Compiler: Visual C++ 2005
PlatformSDK: Installed






Answer this question

Why isn't this call working properly?

  • Gayathri

    I see now, thanks, let me work on that;

    i'll let you know how it turns out.



  • Nihilists

    Alright, so in the struct constructor

    typedef struct icPlayerInformation_Data

    {

    *variables (marked as pointers within the struct)

    icPlayerInformation_Data::icPlayerInformation_Data()

    {

    icPlayerInformation_Data *pl_Statistics;
    pl_Statistics = new icPlayerInformation_Data;

    }

    };



  • akois

    Inside the constructor, you should set sensible default values. Ideally, you'd call new on any pointers inside the struct, and therefore provide a destructor that calls delete on them. If that doesn't make sense, all pointers not initialised should be set to NULL in the constructor.



  • lazy j

    nono, I answered my question about 5minutes ago...
    I forgot to name it:

    LoadGameData LoadGame;
    LoadGame.load_SaveData_Variables();

    However, now my program locksup and gives me this windows encoded message:

    /////////////////////////// ERROR MESSAGE ///////////////////////////////
    Unhandled exception at 0x00403eca in ic_System.exe: 0xC0000005: Access violation writing location 0x00000000.

    Reading from file: C:\19731.txt
    1 Item of information in there for test.

    /////////////////////////// CODE //////////////////////////////////
    void LoadGameData::load_SaveData_Variables()
    {

    ifstream inFile;
    inFile.open( FILENAME );

    icPlayerInformation_Data pl_Statistics;

    do
    {

    inFile >> pl_Statistics.pl_Save_Location;

    } while( !inFile.eof() );

    cout << "Player's Save Location: " << pl_Statistics.pl_Save_Location << ".";

    inFile.close();
    inFile.clear();

    };

    Of course there will be more information to it, and eventually turn it from *.txt to *.dat for security reasons. However, it is strange to me; I've been coding for a while; but taking a break from it for a couple years, gotta relearn so much...

    Thanks for any advice you can give me.

    This is the only thing running at the moment from void main(){} declared as such:

    void main()
    {

    LoadGameData DataLocation;
    DataLocation.load_SaveData_Variables();

    }

    Which enters into the class member function above.

    Definition of the class is:

    class LoadGameData
    {

    private:
    char PlayerInformation;
    icPlayerInformation_Data* pl_statistics;

    public:
    LoadGameData();
    bool load_SaveData_Open();
    void load_SaveData_Variables();
    bool load_SaveData_Close();

    };

    I'm not sure; but possibly did I initialize the variable pl_statistics too much

    Private Class Member && Declared in the Member Function

    Thanks



  • Dr. G

    Thanks a lot, that cleared up that issue. I misspelled the header name...

    However, now I get:

    Main.cpp(33) : error C3861: 'load_SaveData_Open': identifier not found.

    // The header "loadGame.h" (Correct Spelling) is #included in the Main.cpp file and such... It has been a while so I am still unsure why this doesn't work.

    Please shed some light on this. Thanks.
    Sorry for the newbish questions.



  • strombringer

    cannot convert from icPlayerInformation_Data * to unsigned int *

    call is:

    icPlayerInformation_Data::icPlayerInformation_Data()

    {

    icPlayerInformation_Data pl_Statistics;

    pl_Statistics.pl_Level = new icPlayerInformation_Data;

    }

    all within typdef struct icPlayerInformation_Data{} icPlayerInformation_Data;



  • Sean Walker

    A struct should provide a constructor anyhow, to set default values. Something like

    struct st

    {

    int myint;

    float myfloat;

    st:st()

    {

    myint = 0;

    myfloat = 1.0;

    }

    }

    you get the idea.



  • Hindin

    Does the header include the header which defines icPlayerInformation_Data As it's a pointer, you can include it in the cpp, so long as you forward declare it, ie put class icPlayerInformation_Data; above this class definition.



  • Alan Robbins

    A class and a struct are exactly the same thing, except that a structs members are public by default, and a classes are private.



  • Biresh Singh

    Where is icPlayerInformation_Data actually defined in ps_en_stats.h

    is pl_en_stats.h included in the header that defines the LoadGameData class

    Probably not because the error you are getting indicates that it doesn't know what icPlayerInformation_Data is.

    Probably the problem is that you aren't including the right header file, or you have misspelt the type (check the case).

    Regards

    Jero



  • PugV

    No need to apologise.

    The error means there is no function of that name in the cpp. Is there



  • sabo

    pl_statistics has plainly been set to NULL somewhere ( which is good, all empty pointers should be NULL ), but you've never set it to point to an instance of the class.

    if (!pl_statistics)

    pl_statistics = new icPlayerInformation_Data();

    Although you could just call new in the constructor, and delete in the destructor. Or you could make it not a pointer.



  • pbrowntwi

    class LoadGameData
    {

    private:
    icPlayerInformation_Data *pl_Statistics;

    public:
    LoadGameData();
    bool load_SaveData_Open();
    void load_SaveData_Variables();
    bool load_SaveData_Close();

    };

    void LoadGameData::load_SaveData_Variables()
    {

    ifstream inFile;
    inFile.open( FILENAME );

    icPlayerInformation_Data *pl_Statistics;

    do
    {

    if( !pl_Statistics )
    {

    pl_Statistics = new icPlayerInformation_Data();

    }

    inFile >> pl_Statistics->pl_Save_Location;
    inFile >> pl_Statistics->pl_Name;
    inFile >> pl_Statistics->pl_Level;
    inFile >> pl_Statistics->icPlayerClass;

    } while( !inFile.eof() );

    cout << "Player's Save Location: " << pl_Statistics->pl_Save_Location << ".";

    inFile.close();

    }

    .\loadGame.cpp(46) : error C2512: 'icPlayerInformation_Data' : no appropriate default constructor available

    Ok so this should be sufficient



  • TLunsf

    icPlayerInformation_Data isn't a class it is a struct;

    /////////////////////////////////// CODE ////////////////////////////////////////////

    typedef struct
    {

    enum
    {

    pl_Warrior, // Weapon Masters.
    pl_WhiteMage, // Divine Healers.
    pl_BlackMage, // Chaotic Destroyers.
    pl_Thief, // Crafty Pilferers.
    pl_Monk, // Godly Fighters.
    pl_BlueMage, // Immortal Elitists.
    pl_Ninja, // Stealthly Killers.
    pl_Knight, // Heroic Paladins.
    pl_RedMage, // Mixture of Blood.
    pl_DarkKnight, // Chaotic Paladins.

    } icPlayerClass;

    char *pl_Save_Location; // Location where player saved.

    // Attributes //
    int pl_Strength; // Player's Strength.
    int pl_Attack; // Player's Attack.
    int pl_Dexterity; // Player's Dexterity.
    int pl_Accuracy; // Player's Accuracy.
    int pl_Agility; // Player's Agility.
    int pl_RangedAccuracy; // Player's Ranged Accuracy.
    int pl_Evasion; // Player's Evasion.
    int pl_Intelligence; // Player's Intelligence.
    int pl_MagicAttackBonus; // Player's Magic Attack Bonus.
    int pl_Mind; // Player's Mind.
    int pl_MagicDefenseBonus; // Player's Magic Defense Bonus.
    int pl_Constitution; // Player's Constitution.

    // Magic Skills //
    int pl_HealingMagicSkill; // Player's Healing Skill.
    int pl_DivineMagicSkill; // Player's Divine Skill.
    int pl_ElementalMagicSkill; // Player's Elemental Skill.
    int pl_DarkMagicSkill; // Player's Dark Skill.
    int pl_EnfeeblingMagicSkill; // Player's Enfeebling Skill.
    int pl_SummoningMagicSkill; // Player's Summoning Skill.
    int pl_BlueMagicSkill; // Player's Skill over Monster Abilities.

    // Weapon Skills //
    unsigned int pl_HandtohandSkill; // Hand-to-Hand Skill.
    unsigned int pl_DaggerSkill; // Dagger Skill.
    unsigned int pl_SwordSkill; // Sword Skill.
    unsigned int pl_GreatSwordSkill; // Great Sword Skill.
    unsigned int pl_KatanaSkill; // Katana Skill.
    unsigned int pl_ClubSkill; // Club Skill.
    unsigned int pl_StaffSkill; // Staff Skill.
    unsigned int pl_AxeSkill; // Axe Skill.
    unsigned int pl_GreatAxeSkill; // Great Axe Skill.
    unsigned int pl_PolearmSkill; // Polearm Skill.
    unsigned int pl_MarksmanshipSkill; // Marksmanship Skill.
    unsigned int pl_ArcherySkill; // Archery Skill.
    unsigned int pl_ThrowingSkill; // Throwing Skill.

    // Misc. Skills //
    unsigned int pl_EvasionSkill; // Evasion Skill.
    unsigned int pl_ParrySkill; // Parry Skill.
    unsigned int pl_ShieldSkill; // Shield Skill.
    unsigned int pl_GuardSkill; // Guard Skill ( Monk ).

    // Player's Elemental Defenses //
    int pl_ElementalResistances;

    // Player's Elemental Bonuses //
    int pl_ElementalBonus;
    char pl_Weapon_Elemental_BonusType;

    // Player's Health and Magic Pool //
    unsigned int pl_HitPoints_Current; // Current HP.
    unsigned int pl_HitPoints_Overall; // Total HP.
    unsigned int pl_MagicPoints_Current; // Current MP.
    unsigned int pl_MagicPoints_Overall; // Total MP.

    // Player's Level and Experience //
    unsigned int pl_Level; // Player's Current Level.
    unsigned int pl_CurrentExperience; // Player's Current Experience.
    unsigned int pl_ExperienceNext; // Experience Needed to Level.

    // Player's Finance //
    unsigned long long pl_Kir; // Money.

    } icPlayerInformation_Data;

    //////////////////////////////////// END CODE ////////////////////////////////////

    does this pose a problem

    as you put it:

    pl_Statistics = new icPlayerInformation_Data();



  • Why isn't this call working properly?