Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

untemplated C++ class with templated constructor has no constructor in SWIG 3, works OK in SWIG 2 #245

Closed
r-owen opened this issue Oct 16, 2014 · 2 comments

Comments

@r-owen
Copy link

r-owen commented Oct 16, 2014

This problem is described in detail here http://stackoverflow.com/questions/26390195/swig-3-wrap-untemplated-class-with-templated-constructor. In summary: I have a C++ class that is not templated but has templated constructors . I was able to make a Python wrapper in SWIG 2, but the same code fails in SWIG 3.0.2 by having the wrapper class's constructor raise AttributeError("No constructor defined")

Here is a self-contained example (from an answer to that query):

price@price-laptop:~/test $ cat test.h

#ifndef TEST_H
#define TEST_H

#include <iostream>
#include <typeinfo>

namespace test {

class Foo
{
public:
    template<typename T>
    Foo(T bar);
    ~Foo() {}
    void working() const {
        std::cout << "WORKING" << std::endl;
    }
};

}

#endif

price@price-laptop:~/test $ cat test.cc

#include "test.h"

namespace test {

template <typename T>
Foo::Foo(T) {
    std::cout << typeid(T).name() << std::endl;
}

template Foo::Foo(int);

}

price@price-laptop:~/test $ cat test.i

%feature("autodoc", "1");
%module(package="test", docstring="test") testLib

%{
#include "test.h"
%}

%include "test.h"

%extend test::Foo {
     %template(Foo) Foo<int>;
}

price@price-laptop:~/test $ clang++ -shared -undefined dynamic_lookup -o libtest.dylib test.cc

@ojwb
Copy link
Member

ojwb commented Oct 16, 2014

What is the exact SWIG version which works?

@r-owen
Copy link
Author

r-owen commented Oct 16, 2014

Our more complex version of this code works with SWIG 2.0.12 and 2.0.4; we have not tried other versions of SWIG.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants