dlltest.cpp

来自「Boost扩展Python应用样例 使用Boost1.32库」· C++ 代码 · 共 45 行

CPP
45
字号
#include <string>

namespace 
{ // Avoid cluttering the global namespace.

  // A couple of simple C++ functions that we want to expose to Python.
  std::string greet() { return "hello, world"; }
  int square(int number) { return number * number; }
}

#include <boost/python/class.hpp>
namespace python = boost::python;

BOOST_PYTHON_MODULE_INIT()
{
  try
  {
    // Create an object representing this extension module.
	  python::module this_module("getting_started1");

    // Add regular functions to the module.
    this_module.def(greet, "greet");
    this_module.def(square, "square");
  }
  catch(...)
  {
    python::handle_exception(); // Deal with the exception for Python
  }
}

/*
#include <boost/python.hpp>
using namespace boost::python;

char const* greet()
{
   return "hello, world";
}


BOOST_PYTHON_MODULE(dlltest)
{
    def("greet", greet);
}
*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?