Force compiler to choose copy constructor with const T& as a parameter
问题 I'm writing a class where I have a templated constructor and copy constructor. Every time I want to call copy constructor with non const object, templated constructor gets chosen. How can I force compiler to choose copy constructor? Here is the mcve: #include <iostream> struct foo { foo() { std::cout << "def constructor is invoked\n"; } foo(const foo& other) { std::cout << "copy constructor is invoked\n"; } template <typename T> foo(T&& value) { std::cout << "templated constructor is invoked