compile error, please help

This is a discussion on compile error, please help within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <string> using namespace std; #define MAX_RACES 20 void DataLoad(); class Races { public: int raceID; string ...

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

    compile error, please help

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    #define MAX_RACES 20
    
    void DataLoad();
    
    class Races
    {
    public:
    	int raceID;
    	string raceName;
    	string raceEner;
    	string raceEP;
    	string raceDesc;
    	float raceAttG[4];
    	float raceResE[3];
    	float raceResP[3];
    	float raceResM[3];
    
    	Races() {};
    
    	void raceInfo (int iValue, string sString[], float dValue[])
    	{
    		raceID = iValue;
    	    raceName = sString[0];
    	    raceEner = sString[1];
    	    raceEP = sString[2];
    	    raceDesc = sString[3];
    		raceAttG[0] = dValue[0];
    		raceAttG[1] = dValue[1];
    		raceAttG[2] = dValue[2];
    		raceAttG[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];
    	}
    
    }DBraces[MAX_RACES], *charRace;
    
    int main()
    {
    	int n;
    	DataLoad();
    
    	cin >> n;
    
    	charRace = &DBraces[n-1];
    
    	cout << charRace->raceID;
    
    	cin >> n;
    
    	return 0;
    }
    
    void DataLoad()
    {
    	{
    		int iRaces = 1;
    	    string sRaces[] = {"a", "a", "a", "a"};
    	    float fRaces[] = {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};
    	    DBraces[0].raceInfo(iRaces, sRaces[], fRaces[]);
    	}
    }
    ERROR
    ------ Build started: Project: Helios RPG - Beta, Configuration: Release Win32 ------
    Compiling...
    Main.cpp
    .\Main.cpp(70) : error C2059: syntax error : ']'
    Build log was saved at "file://c:\Documents and Settings\eng\My Documents\Visual Studio 2008\Projects\Project1\Helios RPG - Beta\Helios RPG - Beta\Release\BuildLog.htm"
    Helios RPG - Beta - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    why it gives me this error

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    	    DBraces[0].raceInfo(iRaces, sRaces[], fRaces[]);
    Just guessing that this is line 70, and if so the empty [] are wrong. If you want to pass an array to a function, you just give it's name. If you want to pass an individual element, you need something inside the [].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    84
    Quote Originally Posted by matsp View Post
    Code:
    	    DBraces[0].raceInfo(iRaces, sRaces[], fRaces[]);
    Just guessing that this is line 70, and if so the empty [] are wrong. If you want to pass an array to a function, you just give it's name. If you want to pass an individual element, you need something inside the [].

    --
    Mats
    oh my, why i never thought about it, thx alot. XD

    btw, do u think that code is a good way to make a database and database loader/initialize?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Not having much idea of what you are actually trying to achieve, I don't know.

    Having said that, you seem to be using an array for transporting data where each element has it's own meaning. It seems like a struct would be a better solution, rather than an array.

    A few other things:
    1. Why not make it a vector<Races> instead of a fixed size array?
    2. Your constructor for races() should zero out the content of your member variables.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    84
    Quote Originally Posted by matsp View Post
    Not having much idea of what you are actually trying to achieve, I don't know.

    Having said that, you seem to be using an array for transporting data where each element has it's own meaning. It seems like a struct would be a better solution, rather than an array.

    A few other things:
    1. Why not make it a vector<Races> instead of a fixed size array?
    2. Your constructor for races() should zero out the content of your member variables.

    --
    Mats
    how using struct will be better? oO

    how do i use vectors?

    and by zero-out u mean yo define all the members as 0 in the default constructor?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C and C++ compile speed
    By swgh in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 01-02-2007, 02:37 PM
  2. Compile as you type
    By Rocketmagnet in forum A Brief History of Cprogramming.com
    Replies: 33
    Last Post: 12-07-2006, 01:36 PM
  3. How to compile mfc libs from platform sdk
    By tjcbs in forum Windows Programming
    Replies: 6
    Last Post: 11-19-2006, 08:20 AM
  4. Compile crashes certain windows
    By Loduwijk in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2006, 09:05 PM
  5. How can I compile C or C++ with Visual Studio .NET?
    By Dakkon in forum C Programming
    Replies: 8
    Last Post: 02-11-2003, 02:58 PM

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