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:
Here's an overview of the questions per chapter:
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.
The default is C++, Java is also possible but not supported.
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.
Hush (The Java AWT toolkit is also possible but not supported).
Read the hush FAQ at http://www.cs.vu.nl/~hush/FAQ/.
Yes. The latest version of the manuals are available on the WWW at http://www.cs.vu.nl/~hush/manuals/.
Mail us! We will fix it as soon as possible. mailto:jrvosse@cs.vu.nl mailto:eliens@cs.vu.nl
See question 1.7
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
Yes. They are located in the directory
/home/hush/examples
See http://www.cs.vu.nl/~oo/1997/FAQ/examples/env.html
/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)
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.
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.
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
A: Check your class definiton for a missing semi-colon.
The following code generates this error (using g++ 2.7.2):
Thanks to Sander van Amerongen.
See the style guid at http://www.cs.vu.nl/~oo/1997/style.html#implementation
See the hush FAQ at http://www.cs.vu.nl/~hush/FAQ/.
Yes, see http://www.cs.vu.nl/~hush/local/checklist.html.
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:
If this is not possible, explicitly initialize the pointer
to NULL:
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:
Hush features fully automatic garbage collection for widgets, and
semi-automatic garbage collection for other hush objects. See the
hush FAQ for more details.
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:
E.g:
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.
If your program does not compile/link, you have to do two things:
If your program gives a runtime error (dumps core), you have to do two things:
Other questions can be directly mailed to oo@cs.vu.nl.
3.5 Why do I get a "return type specification for constructor invalid"
error message?
class A {
public: A();
} // ; missing
A::A() {}
3.6 Why does the compiler complain about my include files?
3.7 Why does the compiler complain about ... ?
3.8 Do you have an error checklist I can use for code inspection?
4. Miscellaneous
4.1 What about memory management?
obj *p = new obj;
obj *p = NULL; // cannot create, don't have parameters yet
.
. // parameters created here
.
p = new obj(...); // parameters available
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?
4.3 What about C++ classes with copy constructors, assignment operators,
default constructors, etc, etc?
1. A default constructor
2. A copy constructor
3. A (virtual) destructor
4. An assignment operator
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
5. More Troubles
5.1 I have read the whole FAQ. I still have questions.
What do I do?
1. Make the directory your are working in readable
for all users (tip: use chmod -R a+rX
1. See 1. above
2. Send the name of this directory AND a gdb stack trace
to oo@cs.vu.nl.
Generated at: Fri Jul 17 14:56:04 1998 by /home/dejavu/bin/faq2html.py