[Issue 4875] New: Allow struct initialization with constructor
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Sep 15 14:46:10 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4875
Summary: Allow struct initialization with constructor
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: websites
AssignedTo: nobody at puremagic.com
ReportedBy: dfj1esp02 at sneakemail.com
--- Comment #0 from Sobirari Muhomori <dfj1esp02 at sneakemail.com> 2010-09-15 14:45:38 PDT ---
If we have a struct
---
struct HANDLE
{
size_t Value=-1;
this(void *ptrValue)
{
Value=cast(size_t)ptrValue;
}
this(size_t intValue)
{
Value=intValue;
}
}
---
it's possible to initialize variables of type HANDLE with values of types void*
and size_t:
---
HANDLE h1=4, h2=null;
---
But it's impossible to initialize class fields and function arguments in the
same way:
---
class File
{
HANDLE Handle=5; //cannot implicitly convert expression (5) of type int to
HANDLE
}
void FFFF(HANDLE){}
FFFF(5);
FFFF(null); //cannot implicitly convert expression (null) of type void* to
HANDLE
---
This complicates porting from C because in C it's a common practice to pass
null as a function argument for a handle value.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list