我正在调查 Dropbox 发布的跨平台库。以下java代码来自它。我想在我的 Visual c++ 中实现同样的东西;先看java代码
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++ 没有静态类定义。以下代码显示错误
class AsyncTask
{
public:
virtual void execute();
public static class CppProxy : public AsyncTask
{
private:
long LocalNativeRef;
CppProxy(long tmpNativeRef)
{
}
void execute()
{
}
};
};
那么我如何实现内部静态类,它是外部类的子类。