C++ : &(std::cout) as template argument

后端 未结 2 1068
长发绾君心
长发绾君心 2020-12-18 07:29

Why isn\'t it possible to pass std::cout\'s address as template argument? Or if it is possible then how?

Here is what I tried:

#include          


        
2条回答
  •  -上瘾入骨i
    2020-12-18 07:38

    Before C++17 removed this restriction, the syntactic form of a template argument for a pointer or reference template parameter was restricted. N4140 [temp.arg.nontype]/1.3 says that it must be

    expressed (ignoring parentheses) as & id-expression, where the id-expression is the name of an object or function, except that the & may be omitted if the name refers to a function or array and shall be omitted if the corresponding template-parameter is a reference

    (std::cout) isn't an id-expression. It's a primary-expression.

    The "(ignoring parentheses)" part was added by Core issue 773, and is apparently meant to permit (&i), not &(i).

提交回复
热议问题