我在调查由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:不要忘记接受其中一个答案(勾选商标),以通知未来的读者您不再需要帮助。没有被接受的答案的问题在堆栈溢出中被视为未关闭。 –