コンパイラエラーC 2662
1563 ワード
コンパイラエラーC 2662
Visual Studio 2005
その他のバージョン
1(合計1)本稿の評価に役立つ-このテーマを評価する
エラーメッセージ「function」:thisポインタをtype 1からtype 2に変換できません.
コンパイラはthisポインタをtype 1からtype 2に変換できません.
このエラーは、constオブジェクトに対して非constメンバー関数を呼び出すことによって発生する可能性があります.可能なソリューション:オブジェクト宣言からconstを削除します. はconstをメンバー関数に追加します.
次の例では、C 2662を生成します.
/clrコンパイルを使用する場合、constまたはvolatileに対して管理タイプ呼び出し関数を限定することはできません.管理クラスの定数メンバー関数を宣言できないため、定数管理オブジェクトのメソッドを呼び出すことはできません.
次の例では、C 2662を生成します.
Visual Studio 2005
その他のバージョン
1(合計1)本稿の評価に役立つ-このテーマを評価する
エラーメッセージ「function」:thisポインタをtype 1からtype 2に変換できません.
コンパイラはthisポインタをtype 1からtype 2に変換できません.
このエラーは、constオブジェクトに対して非constメンバー関数を呼び出すことによって発生する可能性があります.可能なソリューション:
次の例では、C 2662を生成します.
// C2662.cpp
class C {
public:
void func1();
void func2() const{}
} const c;
int main() {
c.func1(); // C2662
c.func2(); // OK
}
/clrコンパイルを使用する場合、constまたはvolatileに対して管理タイプ呼び出し関数を限定することはできません.管理クラスの定数メンバー関数を宣言できないため、定数管理オブジェクトのメソッドを呼び出すことはできません.
// C2662_b.cpp
// compile with: /c /clr
ref struct M {
property M^ Type {
M^ get() { return this; }
}
void operator=(const M %m) {
M ^ prop = m.Type; // C2662
}
};
ref struct N {
property N^ Type {
N^ get() { return this; }
}
void operator=(N % n) {
N ^ prop = n.Type; // OK
}
};
次の例では、C 2662を生成します.
// C2662_c.cpp
// compile with: /c
// C2662 expected
typedef int ISXVD;
typedef unsigned char BYTE;
class LXBASE {
protected:
BYTE *m_rgb;
};
class LXISXVD:LXBASE {
public:
// Delete the following line to resolve.
ISXVD *PMin() { return (ISXVD *)m_rgb; }
ISXVD *PMin2() const { return (ISXVD *)m_rgb; }; // OK
};
void F(const LXISXVD *plxisxvd, int iDim) {
ISXVD isxvd;
// Delete the following line to resolve.
isxvd = plxisxvd->PMin()[iDim];
isxvd = plxisxvd->PMin2()[iDim];
}