www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Error: constructor Foo.this default constructor for structs only

reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
struct Fence
{
	VkFence	fence;
	alias fence this;

	 static struct CreateInfo
	{
		 VkFenceCreateInfo	ci;
		 alias ci this;
		 this(
		       )
		{
		 ci = typeof(ci)(
		 cast(typeof(ci.sType))StructureType.eFenceCreateInfo,
		 null,
		 0);
		 }
	 }
}

I'm not quite sure what this error is saying. Is it that the only 
struct constructor that can have no parameters is  disable 
this(){} ?

If so this is rather annoying as I have to create a new code path 
for the generation of this and 7 other structs. What must the 
code be in this case?

  static struct CreateInfo
{
		 VkFenceCreateInfo	ci = 
VkFenceCreateInfo(cast(typeof(ci.sType))StructureType.eFenceCreateInfo,null,0);
		 alias ci this;
}
?
Mar 07 2016
next sibling parent Alex Parrill <initrd.gz gmail.com> writes:
On Monday, 7 March 2016 at 13:23:58 UTC, Nicholas Wilson wrote:
 I'm not quite sure what this error is saying. Is it that the 
 only struct constructor that can have no parameters is  disable 
 this(){} ?
Yes, this is exactly right. You cannot have a structure with a default constructor, except with disable. You can, however, specify the initial values of fields, as in your second example. Note that you can use typeof on the variable you are currently declaring. VkFenceCreateInfo CI = typeof(CI)(cast(typeof(CI.sType))StructureType.eFenceCreateInfo, null, 0);
Mar 07 2016
prev sibling parent Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Monday, 7 March 2016 at 13:23:58 UTC, Nicholas Wilson wrote:
 struct Fence
 {
 	VkFence	fence;
 	alias fence this;

 	 static struct CreateInfo
 	{
 		 VkFenceCreateInfo	ci;
 		 alias ci this;
 		 this(
 		       )
 		{
 		 ci = typeof(ci)(
 		 cast(typeof(ci.sType))StructureType.eFenceCreateInfo,
 		 null,
 		 0);
 		 }
 	 }
 }

 I'm not quite sure what this error is saying. Is it that the 
 only struct constructor that can have no parameters is  disable 
 this(){} ?

 If so this is rather annoying as I have to create a new code 
 path for the generation of this and 7 other structs. What must 
 the code be in this case?

  static struct CreateInfo
 {
 		 VkFenceCreateInfo	ci = 
 VkFenceCreateInfo(cast(typeof(ci.sType))StructureType.eFenceCreateInfo,null,0);
 		 alias ci this;
 }
 ?
"Solved" by having a default parameter. Results in a deprecation but w/e.
Mar 07 2016