我有以下幾點:在struct構造函數中用「this」關鍵字編譯錯誤? - C++
int main()
{
struct A
{
unsigned char x, y;
A(unsigned char x, unsigned char y)
{
this.x = x; // Error: expression must have class type.
thix.y = y; // Error: expression must have class type.
}
};
return 0;
}
如何正確指struct A
而不是A
構造函數參數的x
和y
變量的x
和y
變量?
謝謝。
@PaulMcKenzie \t即使是結構體也沒有構造函數? – Hatefiend
'this'總是指針。使用'this->'或'(* this)'對其進行解引用。 –
@Hatefiend「C」語言沒有構造函數,沒有析構函數,也沒有成員函數等,這就是爲什麼'C'標記被刪除的原因。 – PaulMcKenzie