LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-24-2006, 05:16 PM   #1
medha
LQ Newbie
 
Registered: Aug 2006
Posts: 9

Rep: Reputation: 0
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?
 
Old 08-24-2006, 05:27 PM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
> 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[])
 
Old 08-24-2006, 05:40 PM   #3
medha
LQ Newbie
 
Registered: Aug 2006
Posts: 9

Original Poster
Rep: Reputation: 0
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;
}
 
Old 08-24-2006, 05:59 PM   #4
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
whats the declaration of id[] look like (paste the code)?
 
Old 08-24-2006, 06:15 PM   #5
medha
LQ Newbie
 
Registered: Aug 2006
Posts: 9

Original Poster
Rep: Reputation: 0
class Mine{
public:
....

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


}
 
Old 08-24-2006, 06:18 PM   #6
medha
LQ Newbie
 
Registered: Aug 2006
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks for your help xhi.
 
Old 08-24-2006, 06:38 PM   #7
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
hmm. im not seeing the problem. what does Statement::setInt look like, the declaration..
 
Old 08-24-2006, 06:50 PM   #8
medha
LQ Newbie
 
Registered: Aug 2006
Posts: 9

Original Poster
Rep: Reputation: 0
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.
 
Old 08-24-2006, 07:16 PM   #9
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
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?
 
Old 08-24-2006, 07:32 PM   #10
medha
LQ Newbie
 
Registered: Aug 2006
Posts: 9

Original Poster
Rep: Reputation: 0
Question

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??!!
 
Old 08-24-2006, 07:36 PM   #11
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
where is i declared at, and what is the error? is it the same one?
 
Old 08-24-2006, 07:39 PM   #12
medha
LQ Newbie
 
Registered: Aug 2006
Posts: 9

Original Poster
Rep: Reputation: 0
ohh, I should've mentioned!
i is int, just declared int i; in the function.
 
Old 08-24-2006, 07:42 PM   #13
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
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???
 
Old 08-24-2006, 07:45 PM   #14
medha
LQ Newbie
 
Registered: Aug 2006
Posts: 9

Original Poster
Rep: Reputation: 0
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;
}
 
Old 08-24-2006, 07:55 PM   #15
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
how about posting the exact ouput from the compiler
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
invalid conversion from `int*' to `socklen_t*' r350 Programming 5 10-02-2011 05:34 PM
invalid conversion from 'long unsigned int*' to 'uint32*' quarry_06 Programming 8 12-23-2005 11:00 AM
passing int array to thread? Thinking Programming 2 09-21-2005 11:00 AM
invalid types int[int] for array subscript scuzzman Programming 2 11-16-2004 09:34 PM
Char array to int without losing value ? Dimitris Programming 3 01-14-2004 12:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration