Re: [Boost-users] boost::tuple problem
At Saturday 2005-01-22 08:22, you wrote:
hello everyone, what's the difference between "tuple<int> t;" and " tuple<int> t();" why tuple<int> t; cout<
this declares a function named t which takes no arguments and returns a tuple<int> it does NOT define a variable named t.
cout<
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Victor A. Wagner Jr. http://rudbek.com The five most dangerous words in the English language: "There oughta be a law"
hello,
I have a problem with conversion of python class instances to shared_ptr
inside python.
I defined an abstract base class in c++ that is used in c++ and in
embedded python. Only shared_ptr to the concrete instances should be
useable. Thus the concrete classes have hidden ctor's. They must provide
a factory method for creating. Copying of an object must be done using a
clone method.
In detail there are two problems to be done in python:
1. Create a shared_ptr to a new class instance by using a class factory
method
2. Clone a python class instance and return a shared_ptr to the new
instance
The example code:
//in c++
class Base
{
public:
virtual ~Base() {}
virtual shared_ptr<Base> clone() const = 0;
virtual std::string name() const = 0;
protected:
Base() {}
};
void whoiam(shared_ptr<Base> pBase) { std::cout << pBase->name(); }
//for better explanation of the context described above an concrete
//class in c++
class DerivedA : public Base
{
public:
static shared_ptr<DerivedA> create(int n, bool b)
{ return shared_ptr<DerivedA>(new DerivedA(n, b)); }
virtual shared_ptr<Base> clone() const
{ return shared_ptr<DerivedA>(new DerivedA(*this)); }
virtual std::string name() const { return "derivedA"; }
protected:
DerivedA(int n, bool b) : _n(n), _b(b) {}
DerivedA(const DerivedA& other) : _n(other._n) {}
private:
int _n;
bool _b;
};
//wrapping base
struct BaseWrapper : public Base, wrapper<Base>
{
shared_ptr<Base> clone() const {return this->get_override("clone")();}
std::string name() const { return this->get_override("name")(); }
};
//export
BOOST_PYTHON_MODULE(test)
{
def("whoiam", &whoiam);
class_
participants (2)
-
Andreas
-
Victor A. Wagner Jr.