[C++-sig] [Py++] const-overloading: how to use it ?

Roman Yakovenko roman.yakovenko at gmail.com
Tue Jul 17 19:30:41 CEST 2007


On 7/17/07, Adrien Saladin <adrien-ml at wizzi.net> wrote:
> Hi,
>
> I have a C++ class that returns reference to internal data. For this I'm using
> two "get" functions, one returning const and one returning non-const (see
> below for the explicit code)
>
> I'm not sure how I should import them with boost python (and py++). Can both
> functions (const and non-const) be imported ? This probably doesn't make
> sense for python ?
>
> Thanks,
> Adrien
>
>
> //-------- this is a code showing what I would like to import : ----
> #include <string>
> #include <vector>
> using std::string ;
>
> class A
> {
> public:
> A(string s){mVstr.push_back(s);};
>
> string& getC(uint i) {return mVstr[i]; };
> const string& getC(uint i) const {return mVstr[i]; };

Well in most cases, it really doesn't make sense. This case is a
little bit different, in a sense that it doesn't matter what function
you are going to expose, the result will be same. ( hint: Python
string  is immutable type ).

--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list