I kepp getting errors in my following code

#include <iostream>
#include <queue>
#include <ctime>
using namespace std;


template <class TYPE>
void randomInit (TYPE array[], int size, int mod) {
	for (int i = 0; i < size; i++) {
		array[i] = rand()%mod;
	}
}

// Prints Array
template <class TYPE>
void printArray (TYPE array[], int size) {
	cout << "{ ";
	for (int i = 0; i < size; i++) {
		cout << array[i] << ", ";
	}
	cout << "\b\b}" << endl;
}

void radixSort (int array[], int n) {

      register int i, j, k, factor;
      const int radix=10;
      const int digits=10;      //the maximum number of digits for a long
      Queue<array> queues[radix];      //integer;
      for(i=0, factor=1; i<digits; factor *=radix, i++)
      {
            for(j=0; j<n; j++)
                  queues[(array[j]/factor)%radix].enqueue(array[j]);
            for(j=k=0; j<radix; j++)
                  while(!queues[j].empty())
                        data[k++]=queues[j].dequeue();
      }



}


void main () {

	srand(time(NULL));
	// Locals
	time_t initial = time(NULL);
	time_t final;

	#define SIZE 10
	#define MOD 10000
	int array[SIZE];
	randomInit(array, SIZE, MOD);

	
	// Sort & Print Integer Array
	initial = time(NULL);

	cout << "Unsorted: ";
	printArray(array, SIZE);
	cout << endl;

	radixSort(array, SIZE);

	cout << "\n  Sorted: ";
	printArray(array, SIZE);
	cout << endl;

	final = time(NULL);
	cout << "time: " << final-initial << "sec" << endl << endl;
}

the errors I am getting are:

line(29) : error C2065: 'Queue' : undeclared identifier
line(29) : error C2065: 'queues' : undeclared identifier
line(33) : error C2065: 'queues' : undeclared identifier
line(33) : error C2228: left of '.enqueue' must have class/struct/union
line(35) : error C2065: 'queues' : undeclared identifier
line(35) : error C2228: left of '.empty' must have class/struct/union
line(35) : fatal error C1903: unable to recover from previous error(s); stopping compilation


7 error(s), 0 warning(s)

Recommended Answers

All 6 Replies

C++ is case sensitive, and standard names tend to be all lower case.

C++ is case sensitive, and standard names tend to be all lower case.

I fix the captial but I still get three errors in my radixSort function(all the other code I kept the same)

void radixSort (int array[], int n) {       
	register int i, j, k, factor;      
	const int radix=10;      
	const int digits=10;      
	//the maximum number of digits for a long      
	queue<array> queue[radix];      //integer;      
	for(i=0, factor=1; i<digits; factor *=radix, i++)      {            
		for(j=0; j<n; j++)                  
			queue[(array[j]/factor)%radix].enqueue(array[j]);            
		for(j=k=0; j<radix; j++)                  
			while(!queue[j].empty())                        
				array[k++]=queue[j].dequeue();      
	}   
}

line(28) : error C2923: 'std::queue' : 'array' is not a valid template type argument for parameter '_Ty'
line(23) : see declaration of 'array'
line(31) : error C2039: 'enqueue' : is not a member of 'std::queue<_Ty>'
1> with
1> [
1> _Ty=int
1> ]
line(34) : error C2039: 'dequeue' : is not a member of 'std::queue<_Ty>'
1> with
1> [
1> _Ty=int
1> ]
line(39) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data

>'std::queue' : 'array' is not a valid template type argument for parameter '_Ty'
array is a variable, not a type. Do you even know how to use template classes? The template parameter specifies the type of the data you want to store. In this case, that would be int .

>'enqueue' : is not a member of 'std::queue<_Ty>'
>'dequeue' : is not a member of 'std::queue<_Ty>'
Generally it helps to read the reference for your library rather than make stuff up. If you did that, you would know that the standard C++ queue class uses push and pop rather than enqueue and dequeue.

void radixSort (int array[], int n) {       
	register int i, j, k, factor;      
	const int radix=10;      
	const int digits=10;      
	//the maximum number of digits for a long      
	queue<int> queue[radix];      //integer;      
	for(
		i=0, factor=1; 
		i<digits; 
	factor *=radix, i++){            
		for(j=0; j<n; j++)                  
			queue[(array
		[j]/factor)%radix].push(array[j]);            
		for(j=k=0; j<radix; j++)                  
			while(!queue[j].empty())                        
				n[k+1]=queue[j].pop();      
	}   
}

line(39) : error C2109: subscript requires array or pointer type


And no I am not good with templates

>subscript requires array or pointer type
Do I look like your personal error translator? These errors are extremely simple to figure out, especially since you're pointed to the line that causes them. Is it so difficult to read n[k+1]=queue[j].pop(); and say to yourself "Hey, n isn't an array, so why am I use it it like one?"

>subscript requires array or pointer type
Do I look like your personal error translator? These errors are extremely simple to figure out, especially since you're pointed to the line that causes them. Is it so difficult to read n[k+1]=queue[j].pop(); and say to yourself "Hey, n isn't an array, so why am I use it it like one?"

Well I even just had my teacher try to figure it out and he cannot. so no need to be be rude. I am surely am not coming here for help no more.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.