home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 12865 < prev    next >
Encoding:
Text File  |  1992-08-25  |  2.0 KB  |  61 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!wupost!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!jvnc.net!darwin.sura.net!uvaarpa!cv3.cv.nrao.edu!laphroaig!cflatter
  3. From: cflatter@nrao.edu (Chris Flatters,208,7209,homephone)
  4. Subject: Re: Turbo C++ vs. Gnu C++
  5. Message-ID: <1992Aug25.190532.3995@nrao.edu>
  6. Sender: news@nrao.edu
  7. Reply-To: cflatter@nrao.edu
  8. Organization: NRAO
  9. References: <1992Aug25.165224.27556@westford.ccur.com>
  10. Date: Tue, 25 Aug 1992 19:05:32 GMT
  11. Lines: 48
  12.  
  13. In article 27556@westford.ccur.com, macdonal@westford.ccur.com (Steve MacDonald) writes:
  14. >I have a question regarding the following code. This compiles fine with the 
  15. >Gnu C++ compiler, but when I compile this on the latest version of Turbo C++
  16. >on a p.c., I get an error. I'll flag the line to the right of where it appears.
  17. >
  18. >#include <stream.h>
  19. >#include <string.h>
  20. >#include <new.h>
  21. >#define endl "\n"
  22. >
  23. >            //Example3_8
  24. >int classcount;        //Accessing an array of class pointers.
  25. >
  26. >class Test{
  27. >public:
  28. >    Test() {
  29. >             print(word = "NO INITIALIZER SUPPLIED");
  30. >         count = ++classcount;
  31. >         }
  32. >
  33. >    Test(char *mess ="HELLO") 
  34. >        {
  35. >         print(word = mess);
  36. >         count = ++classcount;
  37. >         }
  38. >
  39. > [...]
  40. >
  41. >for(int i = 0; i < 10; i++)
  42. >    classptrarray[i] = new Test; ***TURBO C++ yields the following error
  43. >                    message:
  44. >                    Error c:\tc\examples.cpp 58: Ambiguity
  45. >                    between 'Test::Test()' and 'Test::
  46. >                    Test(char near*)' in function main()
  47.  
  48. Turbo C++ is doing the right thing, GNU C++ isn't.
  49.  
  50. For the purposes of argument matching Test::Test(char *mess = "HELLO") is
  51. considered to be two different functions with the signatures Test::Test(char *)
  52. and Test::Test() (see ARM section 13.2, p316).  Since you have explicitly
  53. declared a Test::Test() constructor there is an ambiguity here.  Should
  54. the compiler use the defined Test::Test() or should it use Test::Test(char *mess)
  55. with the default value of mess.
  56.  
  57. The correct behaviour is to report the ambiguity and abort compilation.
  58.  
  59.     Chris Flatters
  60.     cflatter@nrao.edu
  61.