我想知道为什么当带有 bbb 的行没有被注释掉但它之前的行被注释掉时,下面的代码可以按预期编译和工作,但是当用 aaa 标记的行没有被注释掉并且 bbb 行时它确实会失败是:
#include <iostream>
#include <string>
using String = std::string;
struct Person {
String m_name;
explicit Person(String const &name): m_name(name) {}
operator String() const { return "\"" + m_name + "\""; }
};
template<class T> bool isEqual(
T const& a,
//T const& // does NOT compile // aaa
decltype(a) // DOES compile // bbb
b){ return a == b; }
int main()
{
String const plain("plain");
Person const jb("James");
bool b = isEqual(plain, jb);
std::cout << "isEqual(plain, person) is " << ( b ? "true" : "false" ) << "\n";
}