how to use shared keyword in 2.063 version?

Anthony Goins neontotem at gmail.com
Fri May 31 14:26:19 PDT 2013


On Friday, 31 May 2013 at 21:01:49 UTC, Andrey wrote:
> Hello!
>
> I'm trying to use following code:
>
> <======================================>
> //...
>
> class A
> {
> 	private
> 	{
> 		int m_someVar = 10;
> 	}
>
> 	public
> 	{
> 		this()
> 		{
> 		}
> 	}
> }
>
>
> int main(string[] args)
> {
> 	shared A a = null;
> 	a = new shared(A)(); // error.
>
> 	return 0;
> }
> <======================================>
>
> And on compile time, the compiler says "Error: non-shared 
> method main.A.this is not callable using a shared object".
> How can I use an objects as shared, which classes were not 
> defined with "synchronized" or "shared" keyword?
>
>
> Thanks.

To create a shared object you need shared this ctor.

immutable this() for immutable,

and const this() for const.

Check out the change log.  #2 on the list.


More information about the Digitalmars-d-learn mailing list