구조체를 lvalue (변수로 사용할 수 없음)로 사용할 수 없게하는 방법이 있습니까?D struct lvalue 비활성화 할
생성자와 opAssign을 사용하지 않으려했지만, 결국에는 함수에서 할당 할 수 있습니다.
unittest
{
//mystruct doesntCompile;
mystruct shouldntCompile = makeMyStruct();
}
struct mystruct
{
@disable this();
@disable this(this);
@disable void opAssign(ref mystruct);
@disable void opAssign(mystruct);
this(int dummyArgument){}
}
mystruct makeMyStruct()
{
return mystruct(0);
}
당신은'const' 키워드를 찾고 있습니까? –