How to prevent direct public creation of a struct?

Justin Whear justin at economicmodeling.com
Thu May 3 14:48:39 PDT 2012


On Thu, 03 May 2012 17:37:47 -0400, Nick Sabalausky wrote:
> The *key* thing here that I'm not sure how to do is: How do I disallow
> this?:
> 
> auto b = Foo("b"); // Error: I want to *force* the usage of "template
> foo"

The @disable annotation can do this, I believe:
struct Foo
{
	@disable this();   // Cannot use default constructor
}

But this disables it for code within the module as well as outside, so 
you may wish to also add a private constructor.


More information about the Digitalmars-d-learn mailing list