C++ 检索未命名结构的类型,以便在成员函数中使用它
如何获取在成员函数中使用的未命名结构的类型C++ 检索未命名结构的类型,以便在成员函数中使用它,c++,c++14,C++,C++14,如何获取在成员函数中使用的未命名结构的类型 struct { using P = int; // What should be instead of int? bool operator<(const P& r) { return false; } } obj1, obj2; int main() { obj1 < obj2; return 0; } struct{ 使用P=int;//应该用什么来代替int? bool运算符您可以使运算符
struct {
using P = int; // What should be instead of int?
bool operator<(const P& r) {
return false;
}
} obj1, obj2;
int main() {
obj1 < obj2;
return 0;
}
struct{
使用P=int;//应该用什么来代替int?
bool运算符您可以使运算符完美。*此
在->
之后可用。我简化了我问题中的示例,最初我需要它用于静态成员函数。它可以用于静态成员函数吗?它似乎也适用于静态成员函数。静态自动memfun(const p&r)->…
@S.M.真的吗?我犯了错误;这似乎是不可能的。@S.M.Clang拒绝了它,我认为它是正确的(即使我也不确定)。
template <typename P>
auto operator<(const P& r) -> std::enable_if_t<std::is_same_v<P, std::remove_reference_t<decltype(*this)>>, bool> {
return false;
}