Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct X {};
- template<typename T>
- int foo(T n) {
- return n;
- }
- template<>
- int foo<const X&>(const X& n) {
- return -1;
- }
- int main() {
- const X x;
- const X& rx = x;
- int n1 = foo(0); // OK
- int n2 = foo(rx); // ERROR:
- // In instantiation of 'int foo(T) [with T = X]':
- //error: cannot convert 'X' to 'int' in return
- return 0;
- }
- template<typename T>
- int foo(T n) {
- return n;
- }
- template<typename T>
- int foo(T n) {
- return n;
- }
- int foo(const X& n) {
- return -1;
- }
Add Comment
Please, Sign In to add comment