2

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?

3 Answers3

7

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.

  • +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 Jul 28 '10 at 12:14
  • 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. – CB Bailey Jul 28 '10 at 12:33
  • @Charles I feel an SO CW question coming on "Suggest new uses for the export keyword" :-) –  Jul 28 '10 at 12:49
2

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'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++.

Appleshell
  • 7,088
  • 6
  • 47
  • 96
user401947
  • 850
  • 10
  • 18
0

The export keyword has already been discussed here on SO.

Community
  • 1
  • 1
Abizern
  • 146,289
  • 39
  • 203
  • 257