Archived

This topic is now archived and is closed to further replies.

Error compiling test program with boost::python

This topic is 5270 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to compile a simple example with boost:ython using g++ as opposed to using bjam. When I compile I get:
var.cpp:14: `init'' was not declared in this scope
var.cpp:14: parse error before `>'' token
var.cpp:15: ISO C++ forbids declaration of `class_'' with no type
var.cpp:15: template-id `class_<Var>'' in declaration of primary template
var.cpp:16:44: warning: no newline at end of file
My source code is:
var.cpp:14: `init'' was not declared in this scope
var.cpp:14: parse error before `>'' token
var.cpp:15: ISO C++ forbids declaration of `class_'' with no type
var.cpp:15: template-id `class_<Var>'' in declaration of primary template
var.cpp:16:44: warning: no newline at end of file
So I''m assuming that I haven''t included a certain header file, but which one is it? Any help appreciated. Thanks

Share this post


Link to post
Share on other sites
Here you go! lol


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

#include <string>

class Var
{
Var(std::string name) : name(name), value() {}
std::string const name;
float value;
};

class_<Var>("Var", init<std::string>())
.def_readonly("name", &Var::name)
.def_readwrite("value", &Var::value);

Share this post


Link to post
Share on other sites
Ok, here''s the simple answer : all you have to include is boost/python.hpp. The headers in boost/python/ are implementation details.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites