enum
类型的。但是,我需要使用enum
类。有什么建议吗?在这是我的代码:
zoo.h
namespace extzoo
{
namespace intzoo
{
class zoo
{
public:
enum class Size
{
small, medium, large
};
const std::string hello_zoo();
const std::string getname_zoo();
const Size get_size();
void set_size(Size);
private:
Size size;
};
}
}
zoo.cpp
将C++方法暴露到Python
的代码pyintf.cpp
我有以下错误:
[root@localhost enumclass]# g++ -shared -std=c++11 -o pyintf.so -fPIC pyintf.cpp zoo.h zoo.cpp -lboost_python -lpython2.7 -I/usr/include/python2.7
pyintf.cpp: In function ‘void init_module_pyintf()’:
pyintf.cpp:34:2: error: ‘extzoo::intzoo::python’ has not been declared
python::enum_<zoo::Size>("Size")
pyintf.cpp:34:25: error: expected primary-expression before ‘>’ token
python::enum_<zoo::Size>("Size")
pyintf.cpp:35:8: error: request for member ‘value’ in ‘("Size")’, which is of non-class type ‘const char [5]’
.value("small", zoo::small)
pyintf.cpp:35:23: error: ‘small’ is not a member of ‘extzoo::intzoo::zoo’
.value("small", zoo::small)
pyintf.cpp:36:24: error: ‘medium’ is not a member of ‘extzoo::intzoo::zoo’
.value("medium", zoo::medium)
pyintf.cpp:37:19: error: ‘large’ is not a member of ‘extzoo::intzoo::zoo’
.value("large", zoo::large)
与前面的SO question中相同,问题是类方法定义不是在名称空间中定义的。使用
using namespace ...
是为了获得该命名空间内容的可见性,但不是为了定义该命名空间的内容。在相关问题 更多 >
编程相关推荐