struct template help

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jul 12 12:34:46 PDT 2014


On 07/12/2014 12:19 PM, seany wrote:

 > On Saturday, 12 July 2014 at 19:16:52 UTC, Danyal Zia wrote:
 >> On Saturday, 12 July 2014 at 19:09:44 UTC, seany wrote:

 >>>    arc!(string, string[]) * a;
 >>>    a.some_var = "hello";

 >> "a" has not been instantiated. You are declaring it as a pointer to
 >> struct and using its fields without initializing it. "arc!(string,
 >> string[]) a;" will work.
 >
 > For reasons further down in the software, I need to do this with a
 > pointer. How do I do it with a pointer, please?

By making that pointer point to an actual object. :)

     arc!(string, string[]) * a = new arc!(string, string[])();

Shorter syntax:

     auto a = new arc!(string, string[]);

You can assign it later as well:

     arc!(string, string[]) * a;
     // ...
     a = new arc!(string, string[])();

Preferably, don't assign to the member but construct when the 
information is available:

     auto a = new arc!(string, string[])("hello",
                                         ["merhaba", "hola", "bonjour"]);

Ali



More information about the Digitalmars-d-learn mailing list