gpt4 book ai didi

c++ - 出现类似 "Type qualifier ' std 的错误必须是 C++ 中的结构或类名

转载 作者:行者123 更新时间:2023-11-30 04:10:42 25 4
gpt4 key购买 nike

当我编译下面的代码时,出现类型限定符“std”必须是结构或类名的错误。请找到下面的代码-

#include <iostream>

int foo(int i)
{
return 2;
}

double foo(double d)
{
return 4.0;
}

struct Computer
{
int foo(int i)
{
return 8;
}
};

struct Gateway : public Computer
{
double foo(double d)
{
return 16.0;
}
};

int main(int argc, char** argv)
{
Gateway g;

std::cout << foo(1) + foo(1.0) + g.foo(1) + g.foo(1.0) << std::endl;

return 0;
}

请检查并建议如何解决。

最佳答案

Your code compiles and runs fine.

您收到此错误是因为您的编译器不符合 the C++ standard .

Turbo C++已经过时了。

是时候获得一个新的、免费的、符合标准的编译器了。 Clang例如。


在回答你的第二个问题时,在评论中,Gateway::foo 隐藏 Computer::foo,这就是为什么 Gateway::foointdouble 参数调用。如果这不是您想要的,您可以像这样更改您的 struct:

struct Gateway : public Computer
{
using Computer::foo;

double foo(double d)
{
return 16.0;
}
};

See it run!

关于c++ - 出现类似 "Type qualifier ' std 的错误必须是 C++ 中的结构或类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20517800/

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