Skip to content

Template specializations #21

@kwabenantim

Description

@kwabenantim

Summary

Wrappers are created for methods in template specializations that may not have been implemented. In the example below, the Foo(unsigned u) constructor is not implemented in the specialization.

Foo.hpp

template<unsigned DIM_A, unsigned DIM_B>
class Foo : public AbstractFoo<DIM_A, DIM_B>
{
public:
  Foo(unsigned u);
  Foo(unsigned u, double d);
};

// Specialization
template<unsigned DIM_B>
class Foo<1, DIM_B> : public AbstractFoo<1,DIM_B>
{
public:
  Foo(unsigned u, double d);
  Foo(unsigned u);
};

Foo.cpp

template<unsigned DIM_A, unsigned DIM_B>
Foo<DIM_A, DIM_B>::Foo(unsigned u) : AbstractFoo<DIM_A, DIM_B>(u)
{
  // implementation
}

template<unsigned DIM_A, unsigned DIM_B>
Foo<DIM_A, DIM_B>::Foo(unsigned u, double d) : AbstractFoo<DIM_A, DIM_B>(u, d)
{
  // implementation
}

// Specialization
template<unsigned DIM_B>
Foo<1, DIM_B>::Foo(unsigned u, double d) : AbstractFoo<1, DIM_B>(u, d)
{
  // implementation
}

The wrapper below is generated for Foo<1,2>:

py::class_<Foo1_2, Foo1_2_Overloads>, AbstractFoo<1,2> >(m, "Foo1_2")
  .def(py::init<unsigned int>(), py::arg("u"))
  .def(py::init<unsigned int, double>(), py::arg("u"), py::arg("d"))

This results in a linker error:

undefined reference to `Foo<1u, 2u>::Foo(unsigned int)'

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions