c++ - Syntax errors when right shift operator is used as a template parameter -


if take address of right shift operator , pass template parameter, right shift symbol being misread end of template parameter list, , resulting confusion causing multiple errors.

template <class t, void(t::*)(int)> struct templatemagic {}; struct teststruct { void operator>> (int) {} };  int main() { //all errors on line:     templatemagic<teststruct, &teststruct::operator>> >* ptr;  } 

running in microsoft visual studio express 2013 windows desktop version 12.0.31101.00 update 4 gives following errors:

error c2143 : syntax error : missing ';' before '>'

error c2275 : 'teststruct' : illegal use of type expression

error c2833 : 'operator >' not recognized operator or type

as far can tell, operator>> > symbols being broken apart reads operator>, followed terminating > close template arguments, , ending spare > lulz. assume bug.

is there way reword gets recognized valid?

simply adding parentheses around &teststruct::operator>> force msvc parse correctly.

this code compiles with msvc 19.00.23008.0 :

template <class t, void(t::*)(int)> struct templatemagic {}; struct teststruct { void operator>> (int) {} };  int main() {     templatemagic<teststruct, (&teststruct::operator>>) >* ptr;  } 

the "trick" of adding parentheses work in many situations expression ambiguous or misunderstood compiler.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -