LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   invalid types ‘int[int]’ for array subscript (https://www.linuxquestions.org/questions/programming-9/invalid-types-%91int%5Bint%5D%92-for-array-subscript-477068/)

medha 08-24-2006 05:16 PM

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?

xhi 08-24-2006 05:27 PM

> 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[])

medha 08-24-2006 05:40 PM

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;
}

xhi 08-24-2006 05:59 PM

whats the declaration of id[] look like (paste the code)?

medha 08-24-2006 06:15 PM

class Mine{
public:
....

int id[10];
private:
Environment* env;
Connection* con;
Statement *stmt1, *stmt2, *stmt3, *stmt4, *stmt5, *stmt6, *stmt7, *stmt8, *stmt9, *stmt10;


}

medha 08-24-2006 06:18 PM

Thanks for your help xhi.

xhi 08-24-2006 06:38 PM

hmm. im not seeing the problem. what does Statement::setInt look like, the declaration..

medha 08-24-2006 06:50 PM

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.

xhi 08-24-2006 07:16 PM

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?

medha 08-24-2006 07:32 PM

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??!!

xhi 08-24-2006 07:36 PM

where is i declared at, and what is the error? is it the same one?

medha 08-24-2006 07:39 PM

ohh, I should've mentioned!
i is int, just declared int i; in the function.

xhi 08-24-2006 07:42 PM

Quote:

Originally Posted by medha
ohh, I should've mentioned!
i is int, just declared int i; in the function.

is
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???

medha 08-24-2006 07:45 PM

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;
}

xhi 08-24-2006 07:55 PM

how about posting the exact ouput from the compiler


All times are GMT -5. The time now is 12:17 AM.