which way i should better use?

This is a discussion on which way i should better use? within the C++ Programming forums, part of the General Programming Boards category; Code: void raceInfo (int iValue[], string sString[], float dValue[]) { raceIDnu = iValue[0]; racePowe = iValue[1]; raceName = sString[0]; raceEner ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    84

    which way i should better use?

    Code:
    	void raceInfo (int iValue[], string sString[], float dValue[])
    	{
    		raceIDnu = iValue[0];
    		racePowe = iValue[1];
    	    raceName = sString[0];
    	    raceEner = sString[1];
    	    racePowP = sString[2];
    		raceAttr[0] = dValue[0];
    		raceAttr[1] = dValue[1];
    		raceAttr[2] = dValue[2];
    		raceAttr[3] = dValue[3];
    	    raceResE[0] = dValue[4];
    		raceResE[1] = dValue[5];
    		raceResE[2] = dValue[6];
    	    raceResP[0] = dValue[7];
    		raceResP[1] = dValue[8];
    		raceResP[2] = dValue[9];
    	    raceResM[0] = dValue[10];
    		raceResM[1] = dValue[11];
    		raceResM[2] = dValue[12];}
    
    }racesDB[MAX_RACES], *charRace;
    
    void LoadRaces()
    {
    	int iValue_0[] = {1, MANA_S};
    	string sValue_0[] = {"a", "a", "a"};
    	float fValue_0[] = {1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5};
    	racesDB[0].raceInfo(iValue_0, sValue_0, fValue_0);
    
    	int iValue_1[] = {2, SPIRIT_S};
    	string sValue_1[] = {"a", "a", "a"};
    	float fValue_1[] = {1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5};
    	racesDB[1].raceInfo(iValue_1, sValue_1, fValue_1);
    
    	int iValue_2[] = {3, ANCIENA_S};
    	string sValue_2[] = {"a", "a", "a"};
    	float fValue_2[] = {1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5};
    	racesDB[2].raceInfo(iValue_2, sValue_2, fValue_2);
    }
    Code:
    	void raceInfo (int a, int b, string c, string d, string e, float f, float g, float aa, float bb, float cc, float dd,
    		float ee, float ff, float gg, float aaa, float bbb, float ccc, float ddd)
    	{
    		raceIDnu = a;
    		racePowe = b;
    	    raceName = c;
    	    raceEner = d;
    	    racePowP = e;
    		raceAttr[0] = f;
    		raceAttr[1] = g;
    		raceAttr[2] = aa;
    		raceAttr[3] = bb;
    	    raceResE[0] = cc;
    		raceResE[1] = dd;
    		raceResE[2] = ee;
    	    raceResP[0] = ff;
    		raceResP[1] = gg;
    		raceResP[2] = aaa;
    	    raceResM[0] = bbb;
    		raceResM[1] = ccc;
    		raceResM[2] = ddd;}
    
    }racesDB[MAX_RACES], *charRace;
    
    void LoadRaces()
    {
    	racesDB[0].raceInfo(3, ANCIENA_S, "a", "a", "a", 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5);
    
    	racesDB[1].raceInfo(3, ANCIENA_S, "a", "a", "a", 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5);
    
    	racesDB[2].raceInfo(3, ANCIENA_S, "a", "a", "a", 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5);
    }

    just wondering, which way i should better use? (as u can see i'm trying to do a database storage)

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,751
    How about a struct
    Code:
    struct race {
        int ID;
        int power;
        string name;
        string energy;
        // and so on
    };
    Then you can do
    Code:
    race raceDB[] = {
        {
            1, MANA_S, "a", "b"
        },
        {
            2, SPIRIT_S, "a", "b"
        },
        {
            3, ANCIENA_S, "a", "b"
        },
    }
    As you add more things to each race, this will be a lot easier to expand.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    84
    Quote Originally Posted by Salem View Post
    How about a struct
    Code:
    struct race {
        int ID;
        int power;
        string name;
        string energy;
        // and so on
    };
    Then you can do
    Code:
    race raceDB[] = {
        {
            1, MANA_S, "a", "b"
        },
        {
            2, SPIRIT_S, "a", "b"
        },
        {
            3, ANCIENA_S, "a", "b"
        },
    }
    As you add more things to each race, this will be a lot easier to expand.
    thanks, that's a nice idea, but i think ill stay with classes. and i don't need to expand the class anyway so it doesn't matter if it easier to do so or not

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,117
    Quote Originally Posted by ExDHaos
    thanks, that's a nice idea, but i think ill stay with classes.
    structs are classes. If you rather not use aggregates, then develop the struct into a full blown class with member functions, etc.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    84
    Quote Originally Posted by laserlight View Post
    structs are classes. If you rather not use aggregates, then develop the struct into a full blown class with member functions, etc.
    i know structs and classes r pretty much the same (except sturcts and unions's default r public unlike classes) in C++ what i meant is i prefer to use my class version.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21