gpt4 book ai didi

c++ - 为什么我不能通过继承访问这个方法?

转载 作者:太空狗 更新时间:2023-10-29 19:41:45 24 4
gpt4 key购买 nike

<分区>

我有两个简单的类,希望通过传递 int 值来访问公共(public)方法 stuff。为什么我不能用 Bar 的实例来做到这一点?它不应该继承公共(public)方法的东西吗?类型提示为 int 提供了一个 参数,但它无法编译。

class Foo
{
public:
int a;
void stuff(int a){ std::cout << a << std::endl; }
};

class Bar : public Foo
{
protected:
void stuff() { std::cout << "hello world"; }
};



void main()
{
Bar b
b.stuff(3);
}

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