如何为班级成员使用自动类型扣除?例如,以下代码
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在不知道其定义的情况下无法知道返回类型是什么.
我的问题是,如果有任何变通方法或某种编程模式来规避自动返回类型不能用于类成员函数的问题,以防函数的声明和定义被分开.