当前位置: 代码迷 >> 综合 >> 不能使用 auto 的场景
  详细解决方案

不能使用 auto 的场景

热度:1   发布时间:2023-12-06 05:24:06.0

//
//  不能使用 auto 的场景
#include<bits/stdc++.h>
using namespace std;template <typename T>
struct s { ... };void f1()
{s<int> t1;s<auto> t2=t1;          //false auto 无法推导出模板类型
}class A
{auto a=0;               // false auto 不能初始化 类的非静态成员static auto b=0;        // false 类的静态非常量成员 不能在类内部初始化static const auto c=0;  // true
}void f2( auto a ) { ... }    // false auto 必须初始化 但函数形参只有在调用时才会被赋值int main()
{auto a[]={ 1,2,3 };     // false auto 不能对数组初始化return 0;
}

  相关解决方案