gpt4 book ai didi

C++11 decltype 和数据成员

转载 作者:太空宇宙 更新时间:2023-11-04 13:54:41 25 4
gpt4 key购买 nike

<分区>

下面的代码编译没有任何错误:

class foo
{
public:
void some_func() {}
};

class bar
{
private:
foo instance;

public:
auto some_func() -> decltype(instance.some_func()) {}
};

int main() {}

虽然以下代码无法在 MSVC-12.0 中编译:

class foo
{
public:
void some_func() {}
};

class bar
{
private:
foo instance;

public:
auto some_func() -> decltype(instance.some_func());
};

auto bar::some_func() -> decltype(instance.some_func()) {}

int main() {}

它给我以下错误:

error C2228: left of '.some_func' must have class/struct/union
error C2556: 'int bar::some_func(void)' : overloaded function differs only by return type from 'void bar::some_func(void)'
: see declaration of 'bar::some_func'
error C2371: 'bar::some_func' : redefinition; different basic types
: see declaration of 'bar::some_func'

我做错了什么?我该如何解决?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com