
Question:
Program :main.cpp
struct X { int x; }; export template <class T> T const& min(T const&, T const&); int main() { return min(2, 3); }
x.cpp
struct X { int x; }; export template <class T> T const& min(T const &a, T const &b) { return a<b ? a : b; }
error:Compiling with gcc
export.cpp:23: warning: keyword âexportâ not implemented, and will be ignored export.cpp: In function âint main()â: export.cpp:27: error: call of overloaded âmin(int, int)â is ambiguous swap.cpp:16: warning: keyword âexportâ not implemented, and will be ignored
error: Compiling with EDG compiler
export.cpp", line 27: error: more than one instance of overloaded function export.cpp", line 23: error: support for exported templates is disabled swap.cpp", line 16: error: support for exported templates is disabled
Can anyone solve this problem?
Any one explain the usage of export keyword?
Solution:1
Looks like your compiler doesn't support separate template compilation. It is a common practice not use separate compilation with templates and distribute templates in header files. Besides that, I spotted several issues.
- Remove export keyword from the declaration. This should take care of call of overloaded âmin(int, int)â is ambiguous error message. A template may be defined as exported only once in a program.
- X is defined twice. Why?
P.S. I've never seen any code which uses exported templates. A while ago, when I was learning C++, every compiler I tried did not support exported templates. No wonder it's going to be deprecated from C++.
Solution:2
The export keyword is pretty useless and as far as I'm aware EDG is the only compiler to implement it. The keyword is deprecated in C++0x. So as to its usage - don't even consider it.
Solution:3
The export
keyword has already been discussed here on SO.
Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
EmoticonEmoticon