home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15817 < prev    next >
Encoding:
Internet Message Format  |  1992-11-05  |  3.3 KB

  1. Path: sparky!uunet!pipex!warwick!uknet!mcsun!Germany.EU.net!ira.uka.de!uka!news.ira.uka.de!rose
  2. From: rose@t524i5.telematik.informatik.uni-karlsruhe.de (Ortwin Rose)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Problem with DEC C++ ?
  5. Message-ID: <ROSE.92Nov5121723@t524i5.telematik.informatik.uni-karlsruhe.de>
  6. Date: 5 Nov 92 12:17:23 GMT
  7. References: <99917da2@p3.f6.n249.z2.fidonet.org>
  8. Organization: /usr/users/rose/.organization
  9. Lines: 87
  10. NNTP-Posting-Host: t524i5.telematik.informatik.uni-karlsruhe.de
  11. In-reply-to: Gilles_Kohl@spam.fido.de's message of Mon,  2 Nov 92 17:57:00 +0100
  12.  
  13.  
  14. Hi,
  15.  
  16. let me start with a short answer:
  17. The error-message given below is wrong, but it doesn't occur with the
  18. newest release of DEC C++ (rel. 1.2). Now to the details:
  19.  
  20. > During a port of (a subset of) the NIHCL to DEC C++ (from Glocken-
  21. > spiel) we encountered the following problem. In the source given below,
  22. > DEC C++ issues an error while other compilers (we tried AT&T cfront 2.1,
  23. > Glockenspiel, BC++ 3.1) do not complain.
  24. > // --- Cut here ---
  25. > #include <iostream.h>
  26. > class Base {
  27. > public:
  28. >    virtual int f()       { return 1; }
  29. >    virtual int f() const { return 2; }
  30. > };
  31. > class Derived : public Base {
  32. > public:
  33. >    void test();
  34. > };
  35. > void Derived::test()
  36. > {
  37. >    cout << f() << endl;
  38. > }
  39. > main ()
  40. > {
  41. >    Derived k;
  42. >    k.test();
  43. > }
  44. > // --- cut again ---
  45. > cpptest.C:16: error: In this statement, the argument list "" matches more than 
  46. > one "Base::f".
  47.  
  48. Well, a tricky situation. However, according to the ARM, p. 320:
  49.  
  50.   "..."constness" acts as a tie-breaker where needed but does not affect
  51.    argument matching otherwise. This is especially important for ... const
  52.    member functions".
  53.  
  54. Since Derived::test() is called as "k.test()", this means (ARM, p. 317):
  55.  
  56.   "Where a member of a class X is explicitly called for a pointer using the
  57.    '->' operator, this extra argument is assumed to have a type 'const X*' for
  58.    'const' members ... and X* for others. Where the member function is explicitly 
  59.    called for an object using the '.' operator ... this extra argument is
  60.    assumed to have type 'const X&' for const members ... and X& for others."
  61.  
  62. Now, since test() is NOT declared to be a 'const' member function, it will
  63. see the 'X&' type for its extra argument, and should thus call the non-const
  64. function f() of its base-class. Making Derived::test() a const member
  65. function will cause it to call the other instance of f().
  66.  
  67. With regard to your question about using DEC C++:
  68. I am working with DEC C++ for more than 1 year, and I think it is one of
  69. the best C++ compilers available. It is very restrictive, giving you hints
  70. about almost any violations of the ARM. 
  71. By the way, the same code compiles and runs correctly with my release of cxx,
  72. which identifies itself (using the -V switch) as
  73.  
  74.    DEC C++ for ULTRIX on RISC V1.2
  75.  
  76. Thus, if you WRITE code that passed cxx, you can almost be sure that it will 
  77. compile with any other compiler (I am also working with AT&T CC, GNU C++, 
  78. Borland C++ and Zortech C++). However, if you have to PORT something, using 
  79. cxx can be quite time-consuming since you often have to correct many mistakes
  80. the original writers made.
  81.  
  82.  
  83. Regards
  84.  
  85. -- O. Rose
  86.    University of Karlsruhe
  87.    Institute of Telematics
  88.    Germany
  89.  
  90.    rose@telematik.informatik.uni-karlsruhe.de
  91.