Click here to Skip to main content
15,923,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I'm going to implement std::pair<T, U> in swig&python.
T is class and it doesn't have default constructor.
When I make wrapper.cxx via swig, it has a compile error that
error C2512: 'T' : no appropriate default constructor available

It occurs because when create std::pair variable, it calls constructors of T and U.

How can I fix it?

What I have tried:

I have tried to add code following this:

%feature("valuewrapper") std::pair<T, U>;
%ignore std::pair<T, U>::pair();

But it has no effect.
Posted
Updated 31-Mar-17 1:21am

1 solution

I don't know swig but you got a C++ compiler error.

T and U are template parameters that must be replaced with existing class types.
C++ Examples:
std::pair <int, int> p1;
std::pair <int, std::string> p2;
See also pair::pair - C++ Reference[^].

So you have to use it accordingly depending on the types used with std::pair (guessed):
%feature("valuewrapper") std::pair <int, int>;
%ignore std::pair<int, int>::pair();

%feature("valuewrapper") std::pair <int, std::string>;
%ignore std::pair<int, std::string>::pair();
 
Share this answer
 
Comments
Member 11612662 31-Mar-17 21:12pm    
I tried it.
std::pair<MyClass1, MyStruct1>;
But it have no effect.
Jochen Arndt 1-Apr-17 3:01am    
Sorry about that. I have not used swig and can not help more.

But the compiler error is gone?
Member 11612662 2-Apr-17 20:55pm    
Thanks for your advice. But error still exist.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900