[C++-sig] How to add new constructor in a class

2010-06-18 Thread vishal bayskar

In the below example I need to add a constructor A(). How to do that?

class A{
public:
A(int);
int getA();
private:
int a;
};


I have tried add_declaration_code and add_registration_code but it seems
that these will not work for 
the case of contructor.

Does these work and I am doing somthing wrong?


I also tried to create constructor using decl_factory_t.create_constructor()
but I am not able to add the constructor in the wrapper code

Please let me know the possible solution

One more query Can I overwrite some constructor 
If suppose a constructor is declared as private can I change it's access as
a public (or can I overwrite it somehow)?





-- 
View this message in context: 
http://old.nabble.com/How-to-add-new-constructor-in-a-class-tp28924798p28924798.html
Sent from the Python - c++-sig mailing list archive at Nabble.com.

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] Problem with map_indexing_suite

2010-06-18 Thread Damien Dupuis
I'm trying to wrap a whole C++ that contains a lot of access to std::vector and 
std::map.

I managed to wrap vectors but i've got problems with maps.

The following simple example fails to compile with the error:
error: no match for call to ‘(const 
boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning)
 (X*)‘


#include 
#include 
#include 
using namespace boost::python;

class X {
public:
X(std::string s): _s(s) {}
std::string const repr() { return _s; }

private:
std::string _s;
};

class Y {
public:
Y(): _vec(), _map() {};
void addToVec(X* x){ _vec.push_back(x); }
void addToMap(int i, X* x) { _map[i] = x;   }
const std::vector& getXVec()   { return _vec;   }
const std::map& getXMap() { return _map; }

private:
std::vector   _vec;
std::map _map;
};

BOOST_PYTHON_MODULE(pyTEST) {
class_("X", init())
.def("__repr__", &X::repr)
;

class_ >("XVec")
.def(vector_indexing_suite, true>())
;

class_ >("XMap")
.def(map_indexing_suite, true>())
;

class_("Y", init<>())
.def("addToVec", &Y::addToVec)
.def("addToMap", &Y::addToMap)
.def("getXVec" , &Y::getXVec , return_internal_reference<>())
.def("getXMap" , &Y::getXMap , return_internal_reference<>())
;
}



I tried to use boost::shared_ptr instead of X* in this small example and it 
works, but I would like not to have to correct all my existing C++ code to use 
boost::shared_ptr.
And since it works well with std::vector, I think it should work with maps.

Some google search make me think I should add a return_value_policy to the 
__getitem__ method of std::map class, but when I try I get the error
error: address of overloaded function with no contextual type information
I'm clearly doing something wrong here.

Thanks for any help/advice.

FYI: I'm using boost 1.42.0, with g++ 4.2.1 on snow leopard (10.6.3)
 
---
Damien Dupuis





___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig