Bug? Const Class Makes Constructor Const

Steven Schveighoffer schveiguy at gmail.com
Thu Oct 25 19:51:45 UTC 2018


On 10/25/18 3:23 PM, Vijay Nayar wrote:
> void main()
> {
>    const class Bob {
>      this() {
>        bob = null;
>      }
>      Bob bob;
>    }
> 
>    Bob b = new Bob();
> }
> 
> Compiling this program gives the following error:
> 
> onlineapp.d(10): Error: constructor `onlineapp.main.Bob.this() const` is 
> not callable using argument types `()`
> 
> I know that declaring a 'const class' adds 'const' to every member of 
> the class, but does that even include constructors? I'm not sure how one 
> could use a class with a const constructor. Is this a bug?

Generally:

const(Bob) /*or auto*/ b = new const(Bob)();

But the error message there looks really confusing to me.

-Steve


More information about the Digitalmars-d mailing list