Insanity of Unix-land

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2009
Posts: 28
Reputation: PopeJareth is an unknown quantity at this point 
Solved Threads: 3
PopeJareth PopeJareth is offline Offline
Light Poster

Insanity of Unix-land

 
0
  #1
19 Days Ago
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
Attached Files
File Type: h Deque.h (1.7 KB, 2 views)
File Type: h ArrayQueue.h (1.9 KB, 2 views)
File Type: cpp prog5.cpp (4.5 KB, 2 views)
File Type: txt typescript.txt (7.0 KB, 1 views)
File Type: txt prog5b.txt (187 Bytes, 1 views)
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 306
Reputation: JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough 
Solved Threads: 52
JasonHippy's Avatar
JasonHippy JasonHippy is offline Offline
Posting Whiz
 
1
  #2
18 Days Ago
Originally Posted by PopeJareth View Post
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.
  1. #ifndef SYMBOLNAME_DEFINED
  2. #define SYMBOLNAME_DEFINED
  3.  
  4. // The rest of your header code goes here
  5.  
  6. #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.
There are 10 types of people in this world.....
Those who understand binary .....
And those who don't!
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 306
Reputation: JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough 
Solved Threads: 52
JasonHippy's Avatar
JasonHippy JasonHippy is offline Offline
Posting Whiz
 
2
  #3
18 Days Ago
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:
  1. template <class T>
  2. bool Deque<T>::dequeueBack(T &itemRef){
  3. if (this->isEmpty()){//cannot dequeue
  4. //cout<<"Empty dequeueBack in Dequeue\n";
  5. return false;
  6. }
  7. else{//procede dequeuing
  8. itemRef= this->items[this->back];
  9. if (this->back==0)
  10. this->back = MaxQueue-1;
  11. else
  12. this->back--;
  13.  
  14. }
  15. this->count--;
  16. return true;
  17. }

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.
Last edited by JasonHippy; 18 Days Ago at 7:50 am.
Attached Files
File Type: zip Jas_fix.zip (2.7 KB, 4 views)
There are 10 types of people in this world.....
Those who understand binary .....
And those who don't!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 28
Reputation: PopeJareth is an unknown quantity at this point 
Solved Threads: 3
PopeJareth PopeJareth is offline Offline
Light Poster
 
0
  #4
18 Days Ago
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,148
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 531
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator
 
-7
  #5
18 Days Ago
So, mark as solved?
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 28
Reputation: PopeJareth is an unknown quantity at this point 
Solved Threads: 3
PopeJareth PopeJareth is offline Offline
Light Poster
 
0
  #6
18 Days Ago
Originally Posted by jbennet View Post
So, mark as solved?
I knew I forgot something
Thanks XD
Reply With Quote Quick reply to this message  
Reply

Tags
compile, deque, unix

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC