home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- 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
- From: cflatter@nrao.edu (Chris Flatters,208,7209,homephone)
- Subject: Re: Turbo C++ vs. Gnu C++
- Message-ID: <1992Aug25.190532.3995@nrao.edu>
- Sender: news@nrao.edu
- Reply-To: cflatter@nrao.edu
- Organization: NRAO
- References: <1992Aug25.165224.27556@westford.ccur.com>
- Date: Tue, 25 Aug 1992 19:05:32 GMT
- Lines: 48
-
- In article 27556@westford.ccur.com, macdonal@westford.ccur.com (Steve MacDonald) writes:
- >I have a question regarding the following code. This compiles fine with the
- >Gnu C++ compiler, but when I compile this on the latest version of Turbo C++
- >on a p.c., I get an error. I'll flag the line to the right of where it appears.
- >
- >#include <stream.h>
- >#include <string.h>
- >#include <new.h>
- >#define endl "\n"
- >
- > //Example3_8
- >int classcount; //Accessing an array of class pointers.
- >
- >class Test{
- >public:
- > Test() {
- > print(word = "NO INITIALIZER SUPPLIED");
- > count = ++classcount;
- > }
- >
- > Test(char *mess ="HELLO")
- > {
- > print(word = mess);
- > count = ++classcount;
- > }
- >
- > [...]
- >
- >for(int i = 0; i < 10; i++)
- > classptrarray[i] = new Test; ***TURBO C++ yields the following error
- > message:
- > Error c:\tc\examples.cpp 58: Ambiguity
- > between 'Test::Test()' and 'Test::
- > Test(char near*)' in function main()
-
- Turbo C++ is doing the right thing, GNU C++ isn't.
-
- For the purposes of argument matching Test::Test(char *mess = "HELLO") is
- considered to be two different functions with the signatures Test::Test(char *)
- and Test::Test() (see ARM section 13.2, p316). Since you have explicitly
- declared a Test::Test() constructor there is an ambiguity here. Should
- the compiler use the defined Test::Test() or should it use Test::Test(char *mess)
- with the default value of mess.
-
- The correct behaviour is to report the ambiguity and abort compilation.
-
- Chris Flatters
- cflatter@nrao.edu
-