Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 检索未命名结构的类型,以便在成员函数中使用它_C++_C++14 - Fatal编程技术网

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;
}