クラスに仮想メンバー関数がありますが、派生クラスがありません。
仮想メンバー関数は、派生クラスの定義でオーバーライドされます。派生クラスがない場合は影響しません。仮想メンバー関数の呼び出しは、非仮想メンバー関数の呼び出しよりもコストがかかります。そのため、これらのクラスのメンバー関数から仮想キーワードを排除することでパフォーマンスが向上する可能性があります。
現在派生クラスがなくても、将来派生クラスを追加する場合 (または、別のコンテキストでこのコードを再利用する場合) は、メンバー関数を仮想にできます。この場合、 コンテキストによっては仮想キーワードを排除したほうがいいものと、そうでないものがあります。必要に応じて、この警告は無視することができます。
ID |
問題箇所 |
説明 |
---|---|---|
1 |
定義 |
クラスが定義された場所 |
class A { public: virtual void f() { } virtual ~A() throw() { } }; int main() { A *pa = new A; // This call will go through vtable because f is declared virtual. // Since A is never used as a base class, there is no benefit // to declaring f as virtual. If f were not declared virtual // this would compile into a faster direct call. pa->f(); delete pa; return 0; }
© 2010 Intel Corporation. 無断での引用、転載を禁じます。