tags:

views:

148

answers:

2

A namespace-scope declaration or definition of a non-inline function template, a
non-inline member function template, a non-inline member function of a class template or a static data member of a class template may be preceded by the export keyword. If such a template is defined in the same translation unit in which it is declared as exported, the definition is considered to be exported. The first declaration of the template containing the export keyword must not follow the definition.

What is actually meant in the above statement?

Please any one expalin with program?

+3  A: 

This complex paragraph means that if you declare a templated class as exported before defining it, and then in the same translation unit (effectively, file after preprocessing) you actually define the class, the class definition is exported. But if you define the class and then have a prototype with the "export" keyword, it's not.

There, that's English, right?

Borealid
+2  A: 

The export keyword is meant to enable templates being declared in header files, but defined in implementation files - the way it is usually done with any other function.

Unfortunately, compiler manufacturers have more or less ignored the export keyword for the last decade. GCC maintainers and Microsoft will tell you there is not enough "demand" for that feature (how surprising - next-to-no-one supports it, so no-one knows about it, as your question aptly proves). They'll also tell you that it is too difficult to implement effectively.

(Background: That's what the EDG people said in the C++ committee meetings, but the others insisted on adding it to the standard. In the end, the EDG people were the first and, sadly, the only ones to this day who actually implemented this feature in their compiler frontend, as far as I know.)

So, for all practical purposes, you can ignore the above statement. Templates have to be defined in header files, and cannot be "declared" at all, because all compiler frontends except the EDG one are not standard compliant in this regard.

DevSolar