gpt4 book ai didi

c++ - 没有用于调用的匹配函数...继承的 C++ 类中缺少重载

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:14:43 25 4
gpt4 key购买 nike

<分区>

谁能解释一下这是怎么回事。为什么编译器看不到类 A 中没有参数的 hello()?

struct A {
virtual void hello() {}
virtual void hello(int arg) {}
};
struct B : A {
virtual void hello(int arg) {}
};

int main()
{
B* b = new B();
b->hello();
return 0;
}

g++ main.cpp

main.cpp: In function ‘int main()’:
main.cpp:13:11: error: no matching function for call to ‘B::hello()’
main.cpp:13:11: note: candidate is:
main.cpp:7:15: note: virtual void B::hello(int)
main.cpp:7:15: note: candidate expects 1 argument, 0 provided

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