Topic: A weird constructor that worked


Author: donm@ssd.csd.harris.com (Don McCrady)
Date: 1995/04/12
Raw View
In article <3m19fv$17pu@tequesta.gate.net> stidev@gate.net (Solution Technology) writes:

   Path: hawk.hcsc.com!hearye.mlb.semi.harris.com!darwin.sura.net!haven.umd.edu!purdue!lerc.nasa.gov!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!news.sprintlink.net!tequesta.gate.net!navajo.gate.net!stidev
   From: stidev@gate.net (Solution Technology)
   Newsgroups: comp.std.c++
   Date: 6 Apr 1995 17:47:43 GMT
   Lines: 14
   References: <Pine.A32.3.91c.950405170057.51687F-100000@homer23.u.washington.edu>
   NNTP-Posting-Host: navajo.gate.net
   X-Newsreader: TIN [version 1.2 PL2]

   Joseph Laurino (bytewave@u.washington.edu) wrote:

   : Matrix( int r = 1, int c = 1, char* s ) {
   ...
   : the next day and discovered something.  The constructor shouldn't have
   : compiled because Foo( int foo = something, int fool ) is supposed to be
   : illegal in C+.  Could anyone explain this UF() ( Unidentified Function() ).
   :
   Many c++ compilers accept junk that requires more that syntax checking.
   Some even ignore syntax that the compilers haven't added to their semantic
   processing.  You only think you have a C++ compiler.

   Ken Walter

There may also be a previous declaration of Matrix which provided an initalizer
for the third parameter.  E.g., the following is perfectly legal:

    void f(int r, int c, char* s = 0);
    void f(int r = 1, int c = 1, char *s) { ... }

The result is that all three arguments to "f" have defaults.  This may be what's
happening with your Matrix function.  If not, it's a bug in the compiler.
--
___________________________________________________________________________
Don J. McCrady                | The Mayo Clinic was named after its
donm@mail.hcsc.com       | founder, Dr. Ted Clinic.
2010 W. Cypress Creek Rd      |       -- Dave Barry
Ft. Lauderdale  33309         |





Author: stidev@gate.net (Solution Technology)
Date: 1995/04/06
Raw View
Joseph Laurino (bytewave@u.washington.edu) wrote:

: Matrix( int r = 1, int c = 1, char* s ) {
...
: the next day and discovered something.  The constructor shouldn't have
: compiled because Foo( int foo = something, int fool ) is supposed to be
: illegal in C+.  Could anyone explain this UF() ( Unidentified Function() ).
:
Many c++ compilers accept junk that requires more that syntax checking.
Some even ignore syntax that the compilers haven't added to their semantic
processing.  You only think you have a C++ compiler.

Ken Walter






Author: Joseph Laurino <bytewave@u.washington.edu>
Date: 1995/04/05
Raw View
Matrix( int r = 1, int c = 1, char* s ) {
        row = ( r > 0 ) ? r : 1;
        col = ( c > 0 ) ? c : 1;
        matrixName = new char[strlen(s) + 1];
        strcpy( matrixName, s );
 allocMatrix();
}

The preceding code was the constructor for a matrix class
I wrote two days ago.  Everything worked okay until I returned to my code
the next day and discovered something.  The constructor shouldn't have
compiled because Foo( int foo = something, int fool ) is supposed to be
illegal in C+.  Could anyone explain this UF() ( Unidentified Function() ).

Thank you,
-  Joe

//-------------------------------------------------------------------------
//
// Joseph Y. Laurino                          To err is human...     ---
// bytewave@u.washington.edu                  to debug is divine.   |   + +
// http://weber.u.washington.edu/bytewave                 - JYL      ---
//
//-------------------------------------------------------------------------