What is the best explanation for the export keyword in the C++0x standard?

后端 未结 7 1304
后悔当初
后悔当初 2021-02-05 04:50

I know that in the original C++0x standard there was a feature called export.

But I can\'t find a description or explanation of this feature. What is it sup

7条回答
  •  梦谈多话
    2021-02-05 05:15

    Export is a feature that introduces a circular dependency between linker and compiler. As others noted, it allows one translation unit to contain the definition of a template used in another. The linker will be the first to detect this, but it needs the compiler for the instantiation of the template. And this involves real hard work, like name lookup.

    Comeau introduced it first, about 5 years ago IIRC. It worked quite well on the first beta release I got. Even testcases like A<2> using B<2> using A<1> using B<1> using A<0>, worked, if templates A and B came from different TU's. Sure, the linker was repeatedly invoking the compiler, but all name lookups worked OK. Instantiation A<1> found names from A.cpp that were invisible in B.cpp.

提交回复
热议问题