0

Say I have a class Foo:

class Foo {
private:
    std::string bar;
public:
    Foo () {}
    Foo (const std::string& bar_) { this->bar = bar_; }
    std::string get_bar () { return this->bar; }
};

and a Foo python wrapper FooWrapper.pyx:

from libcpp.string cimport string

cdef extern from "Foo.h":
    cdef cppclass Foo:
        Foo ()
        Foo (string)

Is it possible to access std::string bar in the .pyx file, without modifying Foo?

Joe
  • 33
  • 2
  • 8

1 Answers1

2

If you can't access a private member in C++, then you can't access it in Cython as well.

You could try a trick like this that overwrites the "private" keyword: https://stackoverflow.com/a/424125

Community
  • 1
  • 1
Czarek Tomczak
  • 20,079
  • 5
  • 49
  • 56