www.digitalmars.com         C & C++   DMDScript  

D - bug: duplicated constructors

reply "Carlos Santander B." <carlos8294 msn.com> writes:
This code:

class A {
        this() {}
        private:
        this() {}
        this(int b) { a=b; }
        int a;
}
void main() {
        A x=new A();
}

Gives this error: constructor this overloads A () and A () both match
argument list for this. Personally, I was expecting something like
duplicated constructor or something like that. Or at least I was expecting
it to compile just fine since one of the two constructors is private.

Right before posting I tried putting the class in a different module
(because I remembered friendship and such) and I got the same error.

-------------------------
Carlos Santander


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.504 / Virus Database: 302 - Release Date: 2003-07-24
Jul 27 2003
parent reply "Walter" <walter digitalmars.com> writes:
I'm not sure what the bug is, unless it's just an obscure error message!
There are two constructors for A with the same argument list, so it is an
error in the program.

"Carlos Santander B." <carlos8294 msn.com> wrote in message
news:bg240f$t26$1 digitaldaemon.com...
 This code:

 class A {
         this() {}
         private:
         this() {}
         this(int b) { a=b; }
         int a;
 }
 void main() {
         A x=new A();
 }

 Gives this error: constructor this overloads A () and A () both match
 argument list for this. Personally, I was expecting something like
 duplicated constructor or something like that. Or at least I was expecting
 it to compile just fine since one of the two constructors is private.

 Right before posting I tried putting the class in a different module
 (because I remembered friendship and such) and I got the same error.

 -------------------------
 Carlos Santander


 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.504 / Virus Database: 302 - Release Date: 2003-07-24

Jul 28 2003
parent reply "Carlos Santander B." <carlos8294 msn.com> writes:
"Walter" <walter digitalmars.com> wrote in message
news:bg40fp$2seq$1 digitaldaemon.com...
| I'm not sure what the bug is, unless it's just an obscure error message!
| There are two constructors for A with the same argument list, so it is an
| error in the program.
|

I know it's an error in the program, but it shouldn't compile anyway. The
compiler should complain, shouldn't it?

覧覧覧覧覧覧覧覧覧覧覧覧
Carlos Santander


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.504 / Virus Database: 302 - Release Date: 2003-07-24
Jul 28 2003
parent "Walter" <walter digitalmars.com> writes:
"Carlos Santander B." <carlos8294 msn.com> wrote in message
news:bg44kp$30p3$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:bg40fp$2seq$1 digitaldaemon.com...
 | I'm not sure what the bug is, unless it's just an obscure error message!
 | There are two constructors for A with the same argument list, so it is

 | error in the program.
 |

 I know it's an error in the program, but it shouldn't compile anyway. The
 compiler should complain, shouldn't it?

Yes, it should.
Jul 28 2003