Welcome! Log In Create A New Profile


Assignment 2 malik supplied sources do not compile.

Posted by crowne 
Announcements Last Post
Announcement : Programming Students at UNISA School of Computing 06/19/2019 02:01PM
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Assignment 2 malik supplied sources do not compile.
May 05, 2008 01:31AM

As you may note from the time of this posting, I am really fighting against the environment to get the supplied sources to compile.

By supplied sources, I am referring to the files on the unisa cd under \src\MalikDownloads.

You will notice a previous thread "Problem overriding output operator for template class" where Valkeye, cleverly managed to figure out some obscure syntax just to get operator overloading to work. This was not even required for question 1 but would have been a support element used when testing the functions that we are required to submit.
I have now been stuck on question 2, where the un-modified malik sources will not compile, multiple errors are reported, the most disconcerting of which states:
orderedLinkedList.h:47 `first' was not declared in this scope

orderedLinkdedList extends linkedList, and 'first' is a protected member in linkedList and should therefore be visable and in an accessable scope!

Initially I was using Eclipse as an IDE, and after trying everything that I could think of including compiling from command line and checking for errors with the mingw distribution I finally installed the Dev-C++ IDE from the unisa cd, but the problem unsurprisingly remains the same.

Please can the lecturers run though the set-up and verify that their builds of the malik sources are working (especially chapter 5).

According to the preface page xxxi in Malik, the code has been verified and quality assurance tested against Microsoft Visual C++ .NET or Metrowerks CodeWarrior.

I fear that this may be the first year where this course is being presented using the MinGW compiler and the Dev-C++ IDE, and we are experiencing incompatibility issues between the toolset and the study material.

Neil Crow.
avatar Re: Assignment 2 malik supplied sources do not compile.
May 05, 2008 11:00AM
I am having the same problem. I have contacted the lecturer and we are trying to figure this out. I will post here if we manage something.

However if you are badly pressed for time then just remove the operator<< part from the code and make your own member function print() to print the list. And add those 3 protected variables from linkedListType to orderedLinkedListType. I managed to mangle the program in such a way that I am able to write the assignment question but my orderedLinkedListType class isn't the same as the book's.
avatar Re: Assignment 2 malik supplied sources do not compile.
May 05, 2008 11:06PM
It seems GCC 3.4.2 (the one supplied on the 2008 and 2007 CD) has problems with accessing protected members when templates are involved. Someone else who tried a simple application using templates and extension got similar errors regarding missing protected variables.

If anyone managed to compile this program and any other programs that use templates and extensions, could you please post what version of GCC you use?
Re: Assignment 2 malik supplied sources do not compile.
May 05, 2008 11:35PM
Well I downloaded and installed GCC 3.4.5 and tried to compile through eclipse and the bloodshed IDE with no success.
That was on win XP home OS, I guess I'll try compile it under ubuntu next.

If any one of the 34 silent viewers of this thread (since last night) have not experienced any these issues, or have overcome them please speak up - I think I'm going mad, confirmation of that either way would be encouraging...

Does anyone know what compiler was used last year?
avatar Re: Assignment 2 malik supplied sources do not compile.
May 06, 2008 12:05AM
I have spoken to the lecturer and she says that the code comiles correctly by only adding <> after operator<< but mine doesn't. So I was looking around some c++ ebooks and I found (semi) GOOD NEWS!!!

Add the operator<< definition together with the declaration, so you should have this:
template<class Type>
class linkedListType{
  friend ostream& operator<<(ostream& osObject, const linkedListType<Type>& list){
    nodeType<Type> *current; //pointer to traverse the list
    current = list.first;   //set current so that it points to 
					   //the first node
    while(current != NULL){ //while more data to print
      osObject<<current->info<<" ";
      current = current->link;
   return osObject;
And then the operator error goes away (it has something to do with how c++ misunderstands the template definition and thinks that it is something different than it really is, something along those lines)

But the real good news is:

before every protected member refered to in orderedLinkedListType.

For example:
if(linkedListType<Type>::first == current){
  linkedListType<Type>::first = linkedListType<Type>::first->link;

The code should now compile correctly.

The way I kind of understand this is that whenever we use anything related to linkedListType we always have to say linkedListType<Type> somewhere. But in the orderedLinkedListType methods we refer to the variables directly without having defined any linkedListedType<Type> scope from where we are referencing these variables. (note that when extending plain classes there is only 1 type of class that exists, but with a template class there are infinitely many Types and so we must specify that the variables we use come from any linkedListType<Type> )

Also have a look in the next chapter on implementing a stack by using a linkedList. In the derived class the methods need to call methods from the base clase and here they use linkedListType<Type>::methodName(). (which wouldn't be like this when the classes are not templates)

Hope this helps.
Re: Assignment 2 malik supplied sources do not compile.
May 06, 2008 02:06AM
GCC 4.0.3 on ubuntu suffers from the same errors ...
I'll try your suggestions tomorrow.
avatar Re: Assignment 2 malik supplied sources do not compile.
May 06, 2008 11:00AM
Here's the official fix I received from Aron Lazarus this morning:

If are using the newest compiler that was supplied to you this year (mingw_gcc3.4.2.exe), you may have encountered the following problem. Although orderedLinkedListType is derived from linkedListType, the compiler does not associate the inherited data members such as first and count as members of the derived class. The standard says that unqualified names in a template are generally non-dependent and must be looked up when the template is defined. Since the definition of a dependent base class is not known at that time, unqualified names are never resolved to members of the dependent base class. Where names in the template are supposed to refer to base class members or to indirect base classes, they can be made dependent by qualifying them. In this case, this could be achieved by replacing the all references to first, last or count with this->first, or this->count and this->last.
Re: Assignment 2 malik supplied sources do not compile.
May 11, 2008 04:59PM
One solution for overloading the stream insertion operator is to declare the friend function as below

template<class Type>
class linkedListType
template <class U> friend ostream& operator<<(ostream&, const linkedListType<U>& ) ;

... etc

Note that the above has two template declarations, <class Type> and <class U>. It's confusing but after some thought it actually makes sense why it has to be that way.

The above is the recommended syntax from "C++ in a Nutshell" (Nuts), p.189.

The syntax as given by Malik is identified as syntactically WRONG on the same page of Nuts. That might explain why Malik's code doesn't compile winking smiley


P.S. Malik's book is one of the most boring texts I've ever had to wade through.
avatar Re: Assignment 2 malik supplied sources do not compile.
May 20, 2008 01:42PM

I got this error as well, but did not think it was a problem, as I inserted a scope resolution operator back to the base class. As taught in COS112.

ie linkedListType<Type>::first.

I see from above this->first also works, which is easier to use. Less typing.

ummm... this-> will only work when using reference parameters????
Just a thought. Have not tested yet.

I have tested these two ways of resolving the first and count variables on orderedLinkedList. (I downloaded mine from the books website - suppose this should not make a difference.) I mixed the two solutions in the one program with no problems.

I am using DevC++ with gcc-3.4.2 at work. (not updated).
At home using wx-Devcpp. Not sure on the version of gcc. (fully updated).

Re: Assignment 2 malik supplied sources do not compile.
June 17, 2008 09:37AM
I can get the linked lists and derived classes to compile but they don't work. The count can't increment. Does anyone know what to do with the "count" protected variable?

Has anyone considered just making all the variables public - and does that work?

Does anyone have a full working set of:


I have downloaded dozens from the internet from different universities and none compile on our compiler. However at least everyone else has all the missing functions.

This university lecturer (Turkey) has done a great job, and even included test programs.

Source code folders
avatar Re: Assignment 2 malik supplied sources do not compile.
June 17, 2008 03:29PM
Hey all.

The only errors i've encountered have been the operator<< overload for a template class which we discussed the fix in another thread.

I haven't had any other errors with code, the reason being I don't use any of his code, I create all the functions myself. So mine may differ slightly to his (also I don't like some of his style preferences). But if anyone wants I dont mind mailing my notes and code to them (assignments excluded). It's complete but set out slightly differently, and compiled in VS2005. But its only minor changes to get them to compile in Dev C++.

If anyone wants a set just post your email address and i'll zip the source.

Re: Assignment 2 malik supplied sources do not compile.
June 18, 2008 10:49AM
For those of you who started your degrees in 2006 and still have disk 2006.It may be a good idea to reinstall the version of the compiler found on that disk. That version gives fewer problems. Infact the only problem that was encountered with the older version of the compiler is the operator overload problem which was easily solved(see errata on page 26 tutorial letter 101).

Lazarus Aron
avatar Re: Assignment 2 malik supplied sources do not compile.
June 19, 2008 08:21AM

If the code does not compile in the newer version, then there must be changes in the way code must be written. Going back to use an older version compiler is not going to help in the longer term. Then we need to be taught these changes.

With that said, I downloaded the newer version of Visual Studio Express 2008. Like 2005, it is also free. The offline install is about 900 Meg iso file. After installing VC++, I tested the orderedLinkedListType code from Chp 5 in Malik. After inserting <> after the insertion operator as shown in the errata in TUT101, the code compiled and ran with no errors.

So which is the correct "new" method of coding templates and which compiler should be used in the future? I do not mind either, as longer as we get some clarity on the situation.

Re: Assignment 2 malik supplied sources do not compile.
June 20, 2008 09:16AM

The newer version complies more with the latest C++ standards, with respect to templates,than the older version. C++ compilers in general do not comply with all the latest C++ standards.

Regarding the compiler to use, you could use either one (the old or new).Because the old version does not comply with the latest standards, it is more error prone, when doing more advanced template programming. The newer version solves these problems but the changes discussed above need to be made.

I would not say it is a new way of coding templates. It is rather a compiler dependant issue, and it would best just to be aware of the differences.

In terms of cos211x examinations and assignments both coding methods will be marked correct.

Lazarus Aron
Re: Assignment 2 malik supplied sources do not compile.
July 09, 2008 04:23PM
valkeye, please could I have a set of yours. (diannevolek@gmail.com). They have to better than Moron Malik's!!!

You mention that "its only minor changes to get them to compile in Dev C++." I have absolutely no faith in my programming skills thanks to this stupid module so if you have to have a set that works in Dev C++ PLEASE could you let me have it. Alternatively please give me an idea of what I'm supposed to change.
Sorry, only registered users may post in this forum.

Click here to login