invalid types ‘int[int]’ for array subscript
Hi,
When I compile my program, it gives an error at the line: statement->setInt(2,id[i]); program.cc:261: error: invalid types ‘int[int]’ for array subscript id[] and i, both are defined as int. Any suggestions? |
> statement->setInt(2,id[i]);
well there is obviously nothing wrong with that line in that amount of context. how about posting the entire function that that line of code belongs to (including the declaration of id[]) |
Sure, if that helps....I get the same error for each line where I use
stmt4->setInt(X,id[i]) I define the statement stmt4 in the constructor, and id[i] is defined as int - global. void Mine::check_in_suffix() { int support; long long time; ResultSet *rs; try{ stmt4->setInt(1,GAP); stmt4->setInt(2,id[1]); stmt4->setString(3,tracename[1]); stmt4->setInt(4,id[2]); stmt4->setString(5,tracename[2]); stmt4->setInt(6,id[3]); stmt4->setString(7,tracename[3]); stmt4->setInt(8,id[4]); stmt4->setString(9,tracename[4]); stmt4->setInt(10,id[5]); stmt4->setString(11,tracename[5]); rs = stmt4->executeQuery(); while (rs->next()!=0) { support = stmt4->getInt(support); ..... } stmt4->closeResultSet(rs); } catch(SQLException &oraex) { cout << "Error executing statement in CMiner::check_in_suffix: " << oraex.getMessage() < < endl; stmt4->closeResultSet(rs); } reset_suffix(); time = rdtsc1() - time; cout << "Time: chk_in_suffix() - "<< time << endl; } |
whats the declaration of id[] look like (paste the code)?
|
class Mine{
public: .... int id[10]; private: Environment* env; Connection* con; Statement *stmt1, *stmt2, *stmt3, *stmt4, *stmt5, *stmt6, *stmt7, *stmt8, *stmt9, *stmt10; } |
Thanks for your help xhi.
|
hmm. im not seeing the problem. what does Statement::setInt look like, the declaration..
|
Its right here:
http://www.utexas.edu/its/unix/refer...20.htm#1086413 ------------------------------------ setInt() Set a parameter to a C++ int value. Syntax void setInt(unsigned int paramIndex, int x); Parameters paramIndex The first parameter is 1, the second is 2, . . . . x The parameter value. |
i have a feeling im gonna feel pretty stupid when i am done, but i sure dont see what the problem is.
what happens if you replace the array[] with just an integer? does it compile then? |
Yes, it compiles at other places where I use an int.
I tried i = id[1]; stmt4->setInt(2,i); and now it gives me an error at i = id[1]; so its not the stmt class, then what is it??!! |
where is i declared at, and what is the error? is it the same one?
|
ohh, I should've mentioned!
i is int, just declared int i; in the function. |
Quote:
void Mine::check_in_suffix() the function we are dealing with here? i dont see int i declared or used in that function. or are we talking about a different unposted function. or are we talking about this function but with different code??? |
I made the change to the code I posted earlier After I posted it, I changed it as shown below:
void Mine::check_in_suffix() { int support; long long time; ResultSet *rs; int i; try{ stmt4->setInt(1,GAP); /**************************************** Following 2 lines changed/ i=id[1]; // line with error stmt4->setInt(2,i); /**************************************** end of change/ stmt4->setString(3,tracename[1]); stmt4->setInt(4,id[2]); // line with error stmt4->setString(5,tracename[2]); stmt4->setInt(6,id[3]); // line with error stmt4->setString(7,tracename[3]); stmt4->setInt(8,id[4]); // line with error stmt4->setString(9,tracename[4]); stmt4->setInt(10,id[5]); // line with error stmt4->setString(11,tracename[5]); rs = stmt4->executeQuery(); while (rs->next()!=0) { support = stmt4->getInt(support); ..... } stmt4->closeResultSet(rs); } catch(SQLException &oraex) { cout << "Error executing statement in CMiner::check_in_suffix: " << oraex.getMessage() < < endl; stmt4->closeResultSet(rs); } reset_suffix(); time = rdtsc1() - time; cout << "Time: chk_in_suffix() - "<< time << endl; } |
how about posting the exact ouput from the compiler
|
All times are GMT -5. The time now is 12:17 AM. |