63,594
社区成员




//jni.h
struct JNINativeInterface_;
struct JNIEnv_;
#ifdef __cplusplus
typedef JNIEnv_ JNIEnv;
#else
typedef const struct JNINativeInterface_ *JNIEnv;
#endif
class B
{
public:
void foo()
{
cout<<"B::foo()\n";
}
};
template<typename T>
class Ptr
{
T* m_p;
Ptr(const Ptr&);
Ptr& operator=(const Ptr&);
public:
Ptr(T* p=0):m_p(p){}
~Ptr(){delete m_p;}
T* operator->(){return m_p;}
const T* operator->()const{return m_p;}
T& operator*(){return *m_p;}
const T& operator*()const{return *m_p;}
};
typedef Ptr<B> JNIEnv;
void func(JNIEnv* p)
{
(*p)->foo();
}
int main()
{
JNIEnv a(new B);
func(&a);
return 0;
}
typedef JNIEnv_ JNIEnv;
……
struct JNIEnv_ {
const struct JNINativeInterface_ *functions;
#ifdef __cplusplus
jint GetVersion() {
return functions->GetVersion(this);
}
……
…………………………………………………………………………………………………………………………
jweak NewWeakGlobalRef(jobject obj) {
return functions->NewWeakGlobalRef(this,obj);
}
void DeleteWeakGlobalRef(jweak ref) {
functions->DeleteWeakGlobalRef(this,ref);
}
jboolean ExceptionCheck() {
return functions->ExceptionCheck(this);
}
jobject NewDirectByteBuffer(void* address, jlong capacity) {
return functions->NewDirectByteBuffer(this, address, capacity);
}
void* GetDirectBufferAddress(jobject buf) {
return functions->GetDirectBufferAddress(this, buf);
}
jlong GetDirectBufferCapacity(jobject buf) {
return functions->GetDirectBufferCapacity(this, buf);
}
jobjectRefType GetObjectRefType(jobject obj) {
return functions->GetObjectRefType(this, obj);
}
#endif /* __cplusplus */
};
#include <iostream>
int main() {
typedef int** pptr;
int a = 10;
int *p = &a;
pptr pp = &p;
std::cout << *(*pp)<< std::endl;
return 0;
}