Can Someone tell me why these files won't compile on unix but work fine (mostly) in windows?

It looks like unix-land doesn't load the variables from the inherited class QueueArray into the proper scope.

prog5.cpp is supposed to create 3 different types of Deque classes.
each Deque inherits from ArrayQueue

Your help is greatly appreciated =)
Thanks everyone

Attachments
#pragma once
const int MaxQueue = 10;	// maximum Queue size

template <class T>
	class ArrayQueue{
protected:
		T  items[MaxQueue];
        int  front;			// index to front of items[ ]
        int  back;			// index to back of items[ ]
        int  count;			// number of elements in items[ ]

public:
	ArrayQueue();
	ArrayQueue(const ArrayQueue &oQueue);
	bool  isEmpty() const;
	bool  enqueue(T newItem);
	bool  dequeue();
	bool  dequeue(T &queueFront);
	bool  getFront(T &queueFront) const;
	
	virtual ~ArrayQueue();
};

template <class T>
ArrayQueue<T>::ArrayQueue(){ 
	front = 0;
	back = MaxQueue-1;
	count=0;}

template <class T>
ArrayQueue<T>::ArrayQueue( const  ArrayQueue  &oQueue ) {
	front= oQueue.front;
	back= oQueue.back;
	count= oQueue.count;

    int  pos = oQueue.front;
    for( int  i = 0;  i < oQueue.count;  i++ ){
        items[ pos ] = oQueue.items[ pos ];
        pos = (pos + 1) % MaxQueue;
    }
}
template <class T>
ArrayQueue<T>::~ArrayQueue(){ }//delete [] items;}

template <class T>
bool  ArrayQueue<T>::isEmpty( )const{return  count == 0;}
	
template <class T>
bool  ArrayQueue<T>::enqueue( T  newItem )
{
	if( count == MaxQueue ) {
		//cout<<"Queue full on Queue Enqueue\n";
		return  false;
	}
    back = (back + 1) % MaxQueue;
    items[ back ] = newItem;
    count++;
    return  true;
}

template <class T> 
bool  ArrayQueue<T>::dequeue( ){
    if( isEmpty( ) )  return  false;
    front = (front + 1) % MaxQueue;
 count--;
    return  true;
}

template <class T> 
bool  ArrayQueue<T>::dequeue( T  &queueFront ){
	if( isEmpty() ) {
		//cout<<"emptyQueue on Queue dequeue\n";
		return false;

	}
    queueFront = items[ front ];
    front = (front + 1) % MaxQueue;
    count--;
    return  true;
}

template <class T> 
bool  ArrayQueue<T>::getFront( T  &queueFront ) const
{
    if( isEmpty( ) )  return  false;
    queueFront = items[ front ];
    return  true;
}
#pragma once
#include "ArrayQueue.h"
#include <iostream>
using namespace std;

template <class T>
class Deque : public ArrayQueue<T>{

public:
	Deque();
	Deque(const Deque &oQueue);
	bool enqueueFront(T newItem);
	bool dequeueBack(T &itemRef);

	void print();
	void debug();
	~Deque();
	



	};//end class


template <class T>
Deque<T>::Deque():ArrayQueue<T>(){ }

template <class T>
Deque<T>::~Deque(){ }//delete [] items;}

template <class T>
bool Deque<T>::dequeueBack(T &itemRef){
	if (isEmpty()){//cannot dequeue
		//cout<<"Empty dequeueBack in Dequeue\n";
		return false;
	}
	else{//procede dequeuing
		itemRef= items[back];
		if (back==0)
			back = MaxQueue-1;
		else
			back--;
		
	}
	count--;
}

 template <class T>
bool Deque<T>::enqueueFront(T newItem){
	if (count==MaxQueue){//if full
		//cout<<"Dequeu full on enqueueFront "<<newItem<<endl;
		return false;
	}
	else{//not full procede adding item
		if (front ==0){
			front = MaxQueue-1;
			items[front] = newItem;
		}
		else{
			items[--front]=newItem;

		}
		count++;
	return true;
	}
}
template <class T>
void Deque<T>::print(){
	if (isEmpty())
		cout<<"Empty\n";
	else{
	
	for(int i=front; i !=(back+1)%MaxQueue; i=(i+1)%MaxQueue){
		//for(int i=front; i!=back;i=(i+1)%MaxQueue){
		cout<<items[i];
		if((i+1)%MaxQueue !=(back+1)%MaxQueue)
			cout<<"=>";
		else
			cout<<endl;
	
	
	}
		//if(count==MaxQueue)
		//	cout<<items[back]<<endl;
	}
}


template<class T>
void Deque<T>::debug(){
	cout<<"\nDebugging:\n";
	cout<<"F: "<<front;
	cout<<"\tB: "<<back;
	cout<<"\tC: "<<count<<endl;

	for(int i=0;i<MaxQueue;i++){
		cout<<i<<"\t"<<items[i]<<endl;
	}

}
IR i 10
IR i 12
IF i 4
P
DF i
IF c A
IR f 1.23
DF c
IF f 1.57
IF i 15
P
DF c
IF i 1
IR i 2
IF i 5
IR i 27
IF i 41
IF i 9
IR i 25
IR i 37
h
P
DF i
DF i
DR i
P
Q
Script started on Sat 07 Nov 2009 09:18:52 PM CST
]0;cs331106@cs:~/prog[cs331106@cs prog]$ g++ prog5.cpp
Deque.h: In member function bool Deque<T>::dequeueBack(T&):
Deque.h:33: error: there are no arguments to isEmpty that depend on a template parameter, so a declaration of isEmpty must be available
Deque.h:33: error: (if you use -fpermissive, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
Deque.h:38: error: items was not declared in this scope
Deque.h:38: error: back was not declared in this scope
Deque.h:45: error: no post-decrement operator for type
Deque.h: In member function bool Deque<T>::enqueueFront(T):
Deque.h:50: error: invalid operands of types <unresolved overloaded function type> and const int to binary operator==
Deque.h:55: error: front was not declared in this scope
Deque.h:57: error: items was not declared in this scope
Deque.h:60: error: items was not declared in this scope
Deque.h:63: error: no post-increment operator for type
Deque.h: In member function void Deque<T>::print():
Deque.h:69: error: there are no arguments to isEmpty that depend on a template parameter, so a declaration of isEmpty must be available
Deque.h:73: error: front was not declared in this scope
Deque.h:73: error: back was not declared in this scope
Deque.h:75: error: items was not declared in this scope
Deque.h: In member function void Deque<T>::debug():
Deque.h:92: error: front was not declared in this scope
Deque.h:93: error: back was not declared in this scope
Deque.h:94: error: no match for operator<< in (std::cout << "\011C: ") << std::count
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:67: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:78: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:90: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:241: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:264: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:102: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:125: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:157: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:183: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:215: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:288: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:311: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:361: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:335: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:384: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:407: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:430: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:597: note:                 std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:657: note:                 std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*) [with _CharT = char, _Traits = std::char_traits<char>]
Deque.h:97: error: items was not declared in this scope
]0;cs331106@cs:~/prog[cs331106@cs prog]$ exit
exit

Script done on Sat 07 Nov 2009 09:19:03 PM CST

Can Someone tell me why these files won't compile on unix but work fine (mostly) in windows?

It looks like unix-land doesn't load the variables from the inherited class QueueArray into the proper scope.

prog5.cpp is supposed to create 3 different types of Deque classes.
each Deque inherits from ArrayQueue

Your help is greatly appreciated =)
Thanks everyone

One thing that immediately strikes me is that you are using #pragma once, which as far as I am aware is a preprocessor command that is used solely by Microsoft compilers. So perhaps using traditional inclusion guards might help here. e.g.

#ifndef SYMBOLNAME_DEFINED
#define SYMBOLNAME_DEFINED

// The rest of your header code goes here

#endif // SYMBOLNAME_DEFINED

I'm thinking that because gcc doesn't recognise the #pragma command, it therefore sees no inclusion guards in your code. So perhaps that could be causing things to go a little screwy with gcc.

Also between lines 45 and 46 of the bool Deque<T>::dequeueBack(T &itemRef) function in "Deque.h" you need to add a 'return true', otherwise you'll get some errors or warnings from the compiler (in both *nix and microsoft environments.)

I've not got a *nix box in front of me at the moment, so I can't test this, but replacing all instances of '#pragma once' with traditional (gcc and MS compatible) inclusion guards and then adding the 'return true' to "Deque.h" would at least be a step in the right direction, if not the complete solution to your problem!

Anyway, give that a go and let me know how you get on!
Cheers for now,
Jas.

Aha,
I've just fired up one of my linux boxes, I've created a project in codeblocks using your files. I've made my suggested changes and and tried compiling... And there are still compiler errors.

The problem seems to be regarding the base class members (from ArrayQueue.h) in the Deque class. For some reason g++ doesn't seem to recognise the protected members from ArrayQueue.h like front, back, count, items etc.

I'm not sure if there's a compiler switch to enable the compiler to recognise these correctly, but I've found that if you reference the base-class members using the 'this' pointer in Deque.h, then the compiler errors disappear.

Here's a snippet from Deque.h to show you what I mean:

template <class T>
bool Deque<T>::dequeueBack(T &itemRef){
	if (this->isEmpty()){//cannot dequeue
		//cout<<"Empty dequeueBack in Dequeue\n";
		return false;
	}
	else{//procede dequeuing
		itemRef= this->items[this->back];
		if (this->back==0)
			this->back = MaxQueue-1;
		else
			this->back--;

	}
	this->count--;
	return true;
}

Anyways, the program now compiles without errors or warnings on windows and *nix. A .zip is attached with my changes applied.

In order to ensure that my changes haven't introduced any bugs to your code (apologies if any have crept in there!); you might want to ensure that the program still works in the way you originally intended it to.

Cheers for now,
Jas.

[EDIT]
p.s. I'm fairly new to *nix programming myself...Up until recently I've only ever developed on Windows (so yes, I'm a bit wintarded!). The little *nix programming I have done so far has been for my own amusement.
Anyways, out of curiosity I've done a bit of digging on other forums on this matter and it seems that on *nix, the 'this->' syntax is the norm when attempting to access base class members in derived types.
As far as I understand it, when 'this' is used; if the G++ compiler cannot find a class member/variable in the local scope it will also look for it in any base classes.
I'm not sure if 'this' is needed to access the base class members of all derived types or whether it is only templates that require it.

Edited 7 Years Ago by JasonHippy: n/a

It works wonderfully =) So far it appears that no errors have been introduced. You really are amazing.

Thank you very much for you help with that.

This question has already been answered. Start a new discussion instead.