Thread: which way i should better use?

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    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.

  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
    28,412
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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