Overloading + operator in python with a function writen in C++

95 Views Asked by At

is it possible to Overload pythons + operator using the Python C API.

for example if i run this code in python:

C = A+B

id like to be able to call this function written in c++

template<typename T>
QSMatrix<T> QSMatrix<T>::operator+(const QSMatrix<T>& rhs) {
QSMatrix result(rows, cols, 0.0);

for (unsigned i=0; i<rows; i++) {
  for (unsigned j=0; j<cols; j++) {
    result(i,j) = this->mat[i][j] + rhs(i,j);
  }
}

return result;}

is doing this possible?

0

There are 0 best solutions below