说我有一个带有以下代码的.h文件:
class MyClass
{
public:
int Attribute1;
int Attribute2;
MyClass(){};
virtual ~MyClass(){};
virtual void Method1(string var1);
virtual float Method2(float var2);
};
以及具有以下内容的相关.pyx文件:
cdef class PyClass:
cdef MyClass *classptr
[standard __cinit__ and __dealloc__ declarations ]
cdef int Attribute1;
def Method1(self,var1):
self.classptr.Method1(var1)
...和pxd文件:
cdef extern from "mycode.h":
cdef cppclass MyClass:
MyClass() except +
int Attribute1
void Method1(string)
然后我使用setup.py创建一个.so库以导入python模块。
请注意,即使MyClass :: Method2和MyClass :: Attribute2在c ++中存在,在Cython中也没有提及它们,因此它们在.so库中不可见。也许是因为MyClass :: Method1()间接使用了它们,或者只是因为我不打算在python代码中调用它们。
这是不好的做法,很可能会引起问题/奇怪的行为吗? 如果是这样,为什么?