Solve this Error ,while using 'export' keyword in templates?
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 co开发者_StackOverflow中文版mpiler
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?
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.
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++.
The export
keyword has already been discussed here on SO.
精彩评论