views:

93

answers:

3

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?

+7  A: 

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.

anon
+1, EDG is the only compiler to support it and they pushed to remove it from the next standard. It is more of a problem than a solution.
David Rodríguez - dribeas
The export keyword isn't deprecated in C++0x; it's reserved for future use. Its previous meaning hasn't been deprecated; it's been flat out removed - an unusual single stage removal for a standard. </extreme_pedantry>
Charles Bailey
@Charles I feel an SO CW question coming on "Suggest new uses for the export keyword" :-)
anon
+1  A: 

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.

  1. 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.
  2. X is defined twice. Why?

P.S. I never seen any code which uses exported templates. A while age, when I was learning C++, every compiler I tied did not support exported templates. No wander it going to be deprecated from C++.

+1  A: 

The export keyword has already been discussed here on SO.

Abizern