pointer as non-type template argument

后端 未结 2 823
青春惊慌失措
青春惊慌失措 2020-12-03 05:08

When answering this SO question, I found in the Standard (already C++03, still in C++11) that you can only use addresses as non-type template arguments if they\'re of the fo

2条回答
  •  误落风尘
    2020-12-03 05:30

    Consider classes Foo<&X> and Foo<&Y>, both with a static member int Bar. The linker must be able to tell whether your program has 1 or 2 Bar objects. Now consider that the linker is also the party most likely responsible for assigning values to &X and &Y.

    Look at the Standard again. As it's written, the compiler doesn't need to communicate the actual address to the linker. Instead, it passes the id-expression. Linkers are already quite capable of determining whether two id-expression's are the same, even before assigning a numerical address to them.

提交回复
热议问题