Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 11-16-2004, 08:56 PM   #1
Senior Member
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
invalid types int[int] for array subscript

Any ideas as to why I keep getting these error messages:
excercise4.cpp: In member function `void q_type::q(int)':
excercise4.cpp:31: error: invalid types `int[int]' for array subscript
excercise4.cpp: In member function `int q_type::deq()':
excercise4.cpp:42: error: invalid types `int[int]' for array subscript
When trying to compile this:
/* Goal: create a class 'queue' that maintains a circular queue of integers. make the queue size 
100 integers long, and demonstrate its use in a main function */

#include <iostream>
using namespace std;

#define SIZE 100

class q_type {
	int queue; //hold the queue
	int head, tail; //indexes of the head & tail of the queue
	void init(); //init the queue
	void q(int num); //store the queue
	int deq(); //retrieve

//init the queue
void q_type::init() {
	head = tail = 0;

//place a value on the queue
void q_type::q(int num) {
	if(tail + 1 == head || (tail + 1 == SIZE && !head)) {
		cout << "Queue is full.";
	if(tail == SIZE) tail = 0; //cycle
	queue[tail] = num;

//remove a value from the queue
int q_type::deq() {
	if(head == tail) {
		cout << "Queue is empty.";
		return 0;
	if (head == SIZE) head = 0; //cycle
	return queue[head];

int main() {
	q_type q1, q2; //initialize 2 queues
	int i;

	for(i = 0; i <= 10; i++) {
		q2.q(i * i);
	for(i = 0; i <= 10; i++) {
		cout << "Dequeue 1: " << q1.deq() << "\n";
		cout << "Dequeue 2: " << q2.deq() << "\n";

	return 0;
And don't worry - this is not for class or anything. I'm independently trying to (finally) learn C++, but I keep getting jammed up. Probably because my C knowledge hasn't been used in so long.
Old 11-16-2004, 09:31 PM   #2
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
    int queue;


    return queue[head];
That's a problem! You need to declare queue as an array.
Old 11-16-2004, 09:34 PM   #3
Senior Member
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Original Poster
Rep: Reputation: 47
* scuzzman is seriously feeling like an idiot right now

How could I miss that? Thanks a lot


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
passing int array to thread? Thinking Programming 2 09-21-2005 11:00 AM
Char array to int without losing value ? Dimitris Programming 3 01-14-2004 12:08 PM
string to int in C h/w Programming 2 12-05-2003 03:47 PM
int arr[2]={23,12,45}; aditya Programming 1 03-03-2003 09:32 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:43 AM.

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