943,965 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1191
  • C++ RSS
Nov 7th, 2009
0

Insanity of Unix-land

Expand 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
Attached Files
File Type: h Deque.h (1.7 KB, 28 views)
File Type: h ArrayQueue.h (1.9 KB, 36 views)
File Type: cpp prog5.cpp (4.5 KB, 34 views)
File Type: txt typescript.txt (7.0 KB, 34 views)
File Type: txt prog5b.txt (187 Bytes, 37 views)
Similar Threads
Reputation Points: 11
Solved Threads: 3
Light Poster
PopeJareth is offline Offline
29 posts
since Jun 2009
Nov 9th, 2009
1
Re: Insanity of Unix-land
Click to Expand / Collapse  Quote originally posted by PopeJareth ...
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.
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 590
Solved Threads: 123
Practically a Master Poster
JasonHippy is offline Offline
672 posts
since Jan 2009
Nov 9th, 2009
2
Re: Insanity of Unix-land
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:
C++ Syntax (Toggle Plain Text)
  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.
Attached Files
File Type: zip Jas_fix.zip (2.7 KB, 39 views)
Last edited by JasonHippy; Nov 9th, 2009 at 7:50 am.
Reputation Points: 590
Solved Threads: 123
Practically a Master Poster
JasonHippy is offline Offline
672 posts
since Jan 2009
Nov 9th, 2009
0
Re: Insanity of Unix-land
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.
Reputation Points: 11
Solved Threads: 3
Light Poster
PopeJareth is offline Offline
29 posts
since Jun 2009
Nov 9th, 2009
-7
Re: Insanity of Unix-land
So, mark as solved?
Moderator
Featured Poster
Reputation Points: 1800
Solved Threads: 575
Moderator
jbennet is offline Offline
16,520 posts
since Apr 2005
Nov 9th, 2009
0
Re: Insanity of Unix-land
Click to Expand / Collapse  Quote originally posted by jbennet ...
So, mark as solved?
I knew I forgot something
Thanks XD
Reputation Points: 11
Solved Threads: 3
Light Poster
PopeJareth is offline Offline
29 posts
since Jun 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Recusion Function in C++
Next Thread in C++ Forum Timeline: Conversion to string is a problem..Help please





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC