c++ - Why are cv-qualifiers in template parameters ignored? -


I had some code that failed to compile, which is equal to some of the things shown below to dig around After, I came to paragraph 14.1 note 5, which states:

The top-level CV-qualifier on the template-parameter is ignored when determining its type.

My code looks like this:

  #include & lt; Iostream & gt; #include & lt; Typeinfo & gt; Square bar {}; Template & lt; Class T & gt; Zero Funk (TT) {std :: cout & lt; & Lt; Typid (t) .name () & lt; & Lt; "\ N"; } Template & lt; Square T & gt; Zero Funk (Constant T & T) {std :: cout & lt; & Lt; "Constant Reef:" & lt; & Lt; Typid (t) .name () & lt; & Lt; "\ N"; } Int main () {repeatedly; Cost Bar & amp; Constbar = bar; ConstBar; Return 0; }  

This returns the compilation error:

The 'int main ()' error in the
  function: The overloaded call ' Amp;) 'is ambiguous  

Can anyone comment on the reasoning behind this rule in a standard?

The problem with your code is that the function call is ambiguous Constell Bar & amp; Either value or const context can match. G ++ says:

  xx.cpp: 24: error: Call of overloaded 'funk (constant bar & amp)' is unclear  

this There is nothing particularly special with templates - if you overload a non-template function, you get the same error.

And as people have told you from time to time, you will not learn C ++ by reading the standard.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -