假設我有這個簡化類:如何使用union const成員?
class A {
this(const char* result)
{
this.result = result;
}
private:
union{
const char** results;
const char* result;
}
}
編譯失敗constructor app.A.this missing initializer for const field results
。我知道如果在聯合定義中刪除const
限定符,我可以編譯它,但我知道這些成員是const。
編輯:
當我更改代碼:
class A {
this(const char* result)
{
this.U.result = result;
}
private:
union U {
const char** results;
const char* result;
}
}
我得到另一個錯誤:Error: need 'this' for 'result' of type 'const(char*)'
。
順便說一句,我使用的DMD v2.068.2
你確定這是你的常量的使用是正確的?什麼是const? – Kozzi11