[comp.lang.c++] Zortech C++ problems

bertanij@mist.cs.orst.edu (John Bertani) (08/01/88)

I've been having some problems with the Zortech C++ compiler
lately so I like to ask a few of the experienced users to
help me with thesm:

1. On page 175 of Stroustrup is an example of operator overloading
using a class called tiny.  This works using AT&T C++, 1.2.
I added an #include <stream.hpp> and an error function and
these are the errors I received using Zortech C++:

"tiny.cpp", line 25 Syntax error: illegal operand types
Had instead <struct tiny> and <struct tiny>
    int i = c1 + c2;
                   ^
"tiny.cpp", line 27 Syntax error: illegal operand types
Had instead <struct tiny> and <struct tiny>
    c1 = c2 + 2 * c1;
                    ^
"tiny.cpp", line 28 Syntax error: illegal operand types
Had instead <int> and <struct tiny>
Had instead <int> and <struct tiny>
Had instead <struct tiny> and <int>
    c2 = c1 - i;
               ^
"tiny.cpp", line 29 Syntax error: illegal operand types
Had instead <struct tiny> and <int>

--- errorlevel 1


2. On page 178 of Stroustrup is another operator overloading example
using the matrix class. I added the #include <stream.hpp> and the 
following constructor:

matrix::matrix()
{
    for (int i=0; i<4; i++)
	for (int j=0; j<4; j++)
	    m[i][j] = 0.0;
}

However, I get the same error with or without the constructor code.

    return sum;
              ^
"matrix.cpp", line 26 Syntax error: cannot uniquely determine which function 'matrix' to call

--- errorlevel 1

...but there is only one 'matrix' function prototype declared and there
are no other matrix functions in the file.

3. Then there is the counter class example from Wiener & Pinson, page 85
except I put everything in one file.  This works using AT&T C++, 1.2.
These are the errors I get:

	void operator++();
	                 ^
"counter.cpp", line 9 Syntax error: incorrect number of parameters for operator
	void operator--();
	                 ^
"counter.cpp", line 10 Syntax error: incorrect number of parameters for operator
{
^
"counter.cpp", line 15 Syntax error: incorrect number of parameters for operator
{
^
"counter.cpp", line 21 Syntax error: incorrect number of parameters for operator
	my_great_counter++;
	                 ^
"counter.cpp", line 36 Syntax error: cannot uniquely determine which function 'counter' to call
Fatal error: too many errors
--- errorlevel 1

The operator++ and -- functions are unary member functions with no arguments.

4. The next example is taken from Stroustrup, pg 174 and Stroustrup's 
article in Byte, August '88.  It compiles and runs under AT&T C++, 1.2.
Here it is in its entirety:

#include <stream.hpp>

// Example from Stroustrup, Section 6.3.1, pg 174

class complex {
	double re;
	double im;
public:
	complex(double r, double i =0) {re = r; im = i;}
	friend complex operator+(complex,complex);
	friend complex operator*(complex,complex);
	void print(complex);
};

complex operator+(complex c1, complex c2)
{
    return complex(c1.re + c2.re,c1.im + c2.im);
}

complex operator*(complex c1, complex c2)
{
    return complex(c1.re * c2.re,c1.im * c2.im);
}

void complex::print(complex c)
{
    cout << c.re << "," << c.im << "\n";
}

void main()
{
    complex a = complex(5.0);
    complex b = complex(3.0);

    a = b*2;

    print(a);
    print(b);
}

These are the errors I get:

... sorry, this one hung the machine and required a warm boot.

I was able to succesfully compile and run the string class example in
Stroustrup pp 184-187 and the assoc class examples on pages 181-182.

I would appreciate any comments or help.

John Bertani