Pybind11: How to create bindings for a function that takes in a struct as an argument?

Please see below C++ code that I am trying to create python bindings for

struct Config {
  int a;
  int b;
};

void myfunction(const Config &config);

Here is what I have so far,

PYBIND11_MODULE(example, m) {
  py::class_<Config>(m, "Config")
    .def_readwrite("a", &Config::a)
    .def_readwrite("b", &Config::b);

  m.def("myfunction", &myfunction);
}

This compiles, but when I attempt to call the python bindings in python,

import example

config = example.Config;
config.a = 1;
config.b = 2;

example.myfunction(config)

I got the below error

TypeError: myfunction(): incompatible function arguments. The following argument types are supported:
    1. (arg0: example.Config) -> None

Invoked with: <class 'example.Config'>

Can someone let me know what is the right way to create python bindings for a function that takes in a struct as an argument?

Answer

As hinted by @eyllanesc, the problem will be solved by adding a default constructor:

PYBIND11_MODULE(example, m) {
  py::class_<Config>(m, "Config")
    .def(py::init<>())
    .def_readwrite("a", &Config::a)
    .def_readwrite("b", &Config::b);

  m.def("myfunction", &myfunction);
}
import example

config = example.Config();
config.a = 1;
config.b = 2;

example.myfunction(config)