Prac OOP Frequently Asked Questions

Subject: FAQ: Practicum OOP
Version: $Revision: 1.2 $
Last-modified: $Date: 1998/07/17 12:55:32 $

This article contains answers to Frequently Asked Questions about the Practicum Object Oriented Programming at the faculty of Mathematics and Computer Sciences at the Vrije Universiteit in Amsterdam. Please send any comments or suggestions to oo=faq@cs.vu.nl. The latest version is always available via WWW at http://www.cs.vu.nl/~oo/

This FAQ is divided in the following chapters:

  1. General information
  2. Getting Started
  3. Compiling
  4. Miscellaneous
  5. More Troubles
To find the start of a particular chapter, search for the chapter number followed by a dot and a space at the beginning of a line (e.g. to find chapter 3 in vi, type /^3\. /).

Here's an overview of the questions per chapter:

  1. General information
    1. What is 'Practicum OOP'
    2. What programming language do I have to use?
    3. What is C++?
    4. What window toolkit do I have to use?
    5. What is hush
    6. Is the hush documentation available via the WWW?
    7. I think I found a bug in hush. What do I do?
    8. I think I found an error in the hush manuals or documentation. What do I do?
  2. Getting Started
    1. How do I start? Do you have an example directory I can copy?
    2. Do you have more examples?
    3. What environment variables do I need to be able to work with hush?
  3. Compiling
    1. What version of hush do I need?
    2. What compiler do I use to compile my OOP code?
    3. Why do I need different versions of hush when using different compilers?
    4. Why doesn't my boolean type compile properly?
    5. Why do I get a "return type specification for constructor invalid" error message?
    6. Why does the compiler complain about my include files?
    7. Why does the compiler complain about ... ?
    8. Do you have an error checklist I can use for code inspection?
  4. Miscellaneous
    1. What about memory management?
    2. What about memory management in hush?
    3. What about C++ classes with copy constructors, assignment operators, default constructors, etc, etc?
  5. More Troubles
    1. I have read the whole FAQ. I still have questions. What do I do?
To find a particular question, search for the question number followed by a dot, a space, and a Q at the beginning of a line (e.g. to find question 2.3 in vi, type /^2\.3\. Q/).

1. General information

1.1 What is 'Practicum OOP'

Read the Practicum OOP home page at http://www.cs.vu.nl/~oo/ and the information from the "Studiegids" (online version at http://mostar.cca.vu.nl:8880/vak/vak.html?fac=W_I&jaar=1998&count=98.

1.2 What programming language do I have to use?

The default is C++, Java is also possible but not supported.

1.3 What is C++?

C++ is an object-oriented extension of the C programming language. See the C++ FAQ at ftp://rtfm.mit.edu/pub/usenet-by-group/comp.lang.c++/ and http://info.desy.de/user/projects/C++.html for more C++ related info.

1.4 What window toolkit do I have to use?

Hush (The Java AWT toolkit is also possible but not supported).

1.5 What is hush

Read the hush FAQ at http://www.cs.vu.nl/~hush/FAQ/.

1.6 Is the hush documentation available via the WWW?

Yes. The latest version of the manuals are available on the WWW at http://www.cs.vu.nl/~hush/manuals/.

1.7 I think I found a bug in hush. What do I do?

Mail us! We will fix it as soon as possible. mailto:jrvosse@cs.vu.nl mailto:eliens@cs.vu.nl

1.8 I think I found an error in the hush manuals or documentation. What do I do?

See question 1.7

2. Getting Started

2.1 How do I start? Do you have an example directory I can copy?

Yes. You may copy a general example directory

                /home/hush/project
and read the README file.  

More OOP specific examples are at

		/home/oo/hush/version/oo97/example

2.2 Do you have more examples?

Yes. They are located in the directory

                /home/hush/examples

2.3 What environment variables do I need to be able to work with hush?

See http://www.cs.vu.nl/~oo/1997/FAQ/examples/env.html

3. Compiling

3.1 What version of hush do I need?

	/home/oo/hush/version/oo97 

Be sure you consequently use the same version of hush to avoid errors. (Tip: define the location of hush only once, for instance by defining HUSH = /home/oo/hush/version/oo97)

3.2 What compiler do I use to compile my OOP code?

We recommend the use of the GNU compiler (version 2.7.2) (Tip: define CCC=/usr/local/bin/g++)

Problems may arise when object code compiled with different compilers is linked together.

3.3 Why do I need different versions of hush when using different compilers?

Well, first of all you need different versions of the large number of libraries used by hush because of the link-incompatibility of the libraries, as stated above. Additionally, you need different version of the include files to work around a bug (see below) in the (previous version of) the GNU compiler. But we are working on this.

3.4 Why doesn't my boolean type compile properly?

C++ doesn't have a boolean type (yet). If you want to use one, you may define your own boolean, but you will probably be inconsistent with anyone else who had the same clever idea.

For instance, the more recent versions of the GNU g++ compiler have a predefined 'bool' type, with values 'true' and 'false'...

Tip: Use plain 'int', '0' and '1' until C++ gets a properly standardized boolean type...

If you still want to use bool, and be able to compile your code with all hush packages and several compilers, include the file . It defines the type `bool' with const values `true' (1) and `false' (0).

3.5 Why do I get a "return type specification for constructor invalid" error message?

A: Check your class definiton for a missing semi-colon. The following code generates this error (using g++ 2.7.2):

		class A {
		public: A();
		}		// ; missing

		A::A() {}

Thanks to Sander van Amerongen.

3.6 Why does the compiler complain about my include files?

See the style guid at http://www.cs.vu.nl/~oo/1997/style.html#implementation

3.7 Why does the compiler complain about ... ?

See the hush FAQ at http://www.cs.vu.nl/~hush/FAQ/.

3.8 Do you have an error checklist I can use for code inspection?

Yes, see http://www.cs.vu.nl/~hush/local/checklist.html.

4. Miscellaneous

4.1 What about memory management?

Since C++ does not have a garbage collector you should clean up all the (with new created) objects you no longer need. Be sure that you have a delete somewhere in your program for every new you use. Most of the times, 'somewhere' means in the destructor of the object which created the object which needs to be deleted.

Tip: be sure a pointer always points to a valid object or is NULL otherwise. If you declare a pointer, create the corresponding object in the same statement. E.g:

		obj *p = new obj;

If this is not possible, explicitly initialize the pointer to NULL:

		obj *p = NULL;   // cannot create, don't have parameters yet
		.
		.	         // parameters created here
		.
		p = new obj(...); // parameters available

In this way, it is always save to delete a pointer, even if you are not sure it was ever created. (deleting a NULL pointer can do no harm). E.g:

		obj *p = NULL;
		if ( ... )
			obj *p = new obj( ... );

	 	...

		delete p;		// no error if still p == NULL
		p = NULL;		// next delete will be harmless too

4.2 What about memory management in hush?

Hush features fully automatic garbage collection for widgets, and semi-automatic garbage collection for other hush objects. See the hush FAQ for more details.

4.3 What about C++ classes with copy constructors, assignment operators, default constructors, etc, etc?

If you would like to be able to define classes which instantiations can be assigned, declared and passed as arguments just like any other build-in C type variable, you should use the Orthodox Canonical Class Form [Coplien92, page 38]. This means that for a class X; X has at least the following four member functions:

		1. A default constructor
		2. A copy constructor
		3. A (virtual) destructor
		4. An assignment operator

E.g:

		class X { // Sample declaration:
  		public:
    		  X();                    // default ctor
    		  X(const X&);            // copy ctor
    		  virtual ~X();           // dtor
    		  X& operator=(const X&); // assignment
  		private:
   		  char* s;
		};

 		// Sample (and naive) implementation:
                X::X()           { s = new char[12345]; strcpy(s, "");  }
                X::X(const X& x) { s = new char[12345]; strcpy(s, x.s); }
                X::~X()          { delete[] s; }
                X& X::operator=(const X& x)
  			{ strcpy(s, x.s); return *this; }

		// Sample usage: 

		void f(X x) { 	// some function with parameter X:
        		// ...
		}

		main() {     
		  X x1, x2;  // needs default ctor (twice)
		  f(x1);     // needs copy ctor to copy argument  
		  x2 = x1;   // needs assignment
		}            // dtor called (twice) to destroy x1, x2

Note the difference between the implementation of de copy constructor (which needs to create a new instance variable s, and the assignment operator.

See http://www.cs.vu.nl/~oo/1997/FAQ/examples/constructors.cc.txt for more problems with constructors.

5. More Troubles

5.1 I have read the whole FAQ. I still have questions. What do I do?

If your program does not compile/link, you have to do two things:

		1. Make the directory your are working in readable 
		   for all users (tip: use chmod -R a+rX , make sure
		   parent dirs are readable as well) 
		2. Send the name of this directory AND a 
		   list of compiler/linker error messages to oo@cs.vu.nl

If your program gives a runtime error (dumps core), you have to do two things:

		1. See 1. above
		2. Send the name of this directory AND a gdb stack trace
		   to oo@cs.vu.nl.

Other questions can be directly mailed to oo@cs.vu.nl.


Generated at: Fri Jul 17 14:56:04 1998 by /home/dejavu/bin/faq2html.py