相关疑难解决方法(0)

在类成员的上下文中,`auto`返回类型

如何为班级成员使用自动类型扣除?例如,以下代码

struct A
{
  auto foo(); // foo is defined in another file 
};


int main()
{
  A a;
  a.foo();
}
Run Code Online (Sandbox Code Playgroud)

其中foo返回类型auto导致以下错误:

error: function 'foo' with deduced return type cannot be used before it is defined
  a.foo();
    ^
Run Code Online (Sandbox Code Playgroud)

错误是可以理解的,因为编译foo在不知道其定义的情况下无法知道返回类型是什么.

我的问题是,如果有任何变通方法或某种编程模式来规避自动返回类型不能用于类成员函数的问题,以防函数的声明和定义被分开.

c++ class auto c++14

6
推荐指数
1
解决办法
1202
查看次数

标签 统计

auto ×1

c++ ×1

c++14 ×1

class ×1