我在調查由dropbox發佈的跨平臺庫。下面的java代碼是來自它的。 而我想在我的Visual C++中實現相同的東西; 在Java代碼C++類中的內部代理實現
public abstract class AsyncTask
{
public abstract void execute();
public static final class CppProxy extends AsyncTask
{
private final long nativeRef;
private final AtomicBoolean destroyed = new AtomicBoolean(false);
private CppProxy(long nativeRef)
{
if (nativeRef == 0) throw new RuntimeException("nativeRef is zero");
this.nativeRef = nativeRef;
}
private native void nativeDestroy(long nativeRef);
public void destroy()
{
boolean destroyed = this.destroyed.getAndSet(true);
if (!destroyed) nativeDestroy(this.nativeRef);
}
protected void finalize() throws java.lang.Throwable
{
destroy();
super.finalize();
}
@Override
public void execute()
{
assert !this.destroyed.get() : "trying to use a destroyed object";
native_execute(this.nativeRef);
}
private native void native_execute(long _nativeRef);
}
}
先來看看這個Java代碼調用一些JNI C++類(它的AsyncTask的名稱相同)。 因此,它正在java類中實現C++代理來維護jni方面的C++對象。
但我想在MFC的c + +語言,而不是Java語言(通常用於測試目的)做它 所以我實現了從上層java代碼的C++類。 但我發現C++沒有靜態類定義。 Folloing代碼顯示錯誤
class AsyncTask
{
public:
virtual void execute();
public static class CppProxy : public AsyncTask
{
private:
long LocalNativeRef;
CppProxy(long tmpNativeRef)
{
}
void execute()
{
}
};
};
所以,我怎麼能實現它subclsssing課外內部靜態類。
感謝您的親切和詳細的答案。 – MomAndDad
@MomAndDad:不要忘記接受其中一個答案(勾選商標),以通知未來的讀者您不再需要幫助。沒有被接受的答案的問題在堆棧溢出中被視爲未關閉。 –