home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pipex!warwick!uknet!mcsun!Germany.EU.net!ira.uka.de!uka!news.ira.uka.de!rose
- From: rose@t524i5.telematik.informatik.uni-karlsruhe.de (Ortwin Rose)
- Newsgroups: comp.lang.c++
- Subject: Re: Problem with DEC C++ ?
- Message-ID: <ROSE.92Nov5121723@t524i5.telematik.informatik.uni-karlsruhe.de>
- Date: 5 Nov 92 12:17:23 GMT
- References: <99917da2@p3.f6.n249.z2.fidonet.org>
- Organization: /usr/users/rose/.organization
- Lines: 87
- NNTP-Posting-Host: t524i5.telematik.informatik.uni-karlsruhe.de
- In-reply-to: Gilles_Kohl@spam.fido.de's message of Mon, 2 Nov 92 17:57:00 +0100
-
-
- Hi,
-
- let me start with a short answer:
- The error-message given below is wrong, but it doesn't occur with the
- newest release of DEC C++ (rel. 1.2). Now to the details:
-
- > During a port of (a subset of) the NIHCL to DEC C++ (from Glocken-
- > spiel) we encountered the following problem. In the source given below,
- > DEC C++ issues an error while other compilers (we tried AT&T cfront 2.1,
- > Glockenspiel, BC++ 3.1) do not complain.
- >
- > // --- Cut here ---
- >
- > #include <iostream.h>
- >
- > class Base {
- > public:
- > virtual int f() { return 1; }
- > virtual int f() const { return 2; }
- > };
- >
- > class Derived : public Base {
- > public:
- > void test();
- > };
- >
- > void Derived::test()
- > {
- > cout << f() << endl;
- > }
- >
- > main ()
- > {
- > Derived k;
- >
- > k.test();
- > }
- >
- > // --- cut again ---
- >
- > cpptest.C:16: error: In this statement, the argument list "" matches more than
- > one "Base::f".
-
- Well, a tricky situation. However, according to the ARM, p. 320:
-
- "..."constness" acts as a tie-breaker where needed but does not affect
- argument matching otherwise. This is especially important for ... const
- member functions".
-
- Since Derived::test() is called as "k.test()", this means (ARM, p. 317):
-
- "Where a member of a class X is explicitly called for a pointer using the
- '->' operator, this extra argument is assumed to have a type 'const X*' for
- 'const' members ... and X* for others. Where the member function is explicitly
- called for an object using the '.' operator ... this extra argument is
- assumed to have type 'const X&' for const members ... and X& for others."
-
- Now, since test() is NOT declared to be a 'const' member function, it will
- see the 'X&' type for its extra argument, and should thus call the non-const
- function f() of its base-class. Making Derived::test() a const member
- function will cause it to call the other instance of f().
-
- With regard to your question about using DEC C++:
- I am working with DEC C++ for more than 1 year, and I think it is one of
- the best C++ compilers available. It is very restrictive, giving you hints
- about almost any violations of the ARM.
- By the way, the same code compiles and runs correctly with my release of cxx,
- which identifies itself (using the -V switch) as
-
- DEC C++ for ULTRIX on RISC V1.2
-
- Thus, if you WRITE code that passed cxx, you can almost be sure that it will
- compile with any other compiler (I am also working with AT&T CC, GNU C++,
- Borland C++ and Zortech C++). However, if you have to PORT something, using
- cxx can be quite time-consuming since you often have to correct many mistakes
- the original writers made.
-
-
- Regards
-
- -- O. Rose
- University of Karlsruhe
- Institute of Telematics
- Germany
-
- rose@telematik.informatik.uni-karlsruhe.de
-