如何在C++中處理「無法實例化抽象類」錯誤? 我已經看過一些類似的錯誤在這裏,沒有一個看起來是完全一樣的或我有問題。但是,我再次承認,有幾個要過去。以下是編譯錯誤:如何在C++中處理「無法實例化抽象類」錯誤?
這使我這個網頁: http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(C2259);k(VS.ERRORLIST)&rd=true 編譯錯誤C2259是從C++程序,但該頁面調用抽象類的「接口」:
Whenever you derive from an interface and implement the interface methods in the derived class with access permissions other than public, you may receive C2259. This occurs because the compiler expects the interface methods implemented in the derived class to have public access. When you implement the member functions for an interface with more restrictive access permissions, the compiler does not consider them to be implementations for the interface methods defined in the interface, which in turn makes the derived class an abstract class.
There are two possible workarounds for the problem:
Make the access permissions public for the implemented methods.
Use the scope resolution operator for the interface methods implemented in the derived class to qualify the implemented method name with the name of the interface.
壞消息是我已經在課堂上公開了所有的方法:
class AmbientOccluder: public Light {
public:
AmbientOccluder(void);
@dasblinkenlight IIRC,這是可選的。然而,後者默認構造該對象。但不是一個錯誤。另請參閱:http://ideone.com/LWbg6 – Drise 2012-08-06 18:41:22
@dasblinkenlight嗯,不,不需要括號。 – 2012-08-06 18:41:46
@dasblinkenlight是否有太多的Java和C#,是不是? – 2012-08-06 18:42:03