gpt4 book ai didi

c++ - 在 C++ 中声明具有另一个类型的类中的属性

转载 作者:搜寻专家 更新时间:2023-10-31 00:58:39 26 4
gpt4 key购买 nike

<分区>

我是 C++ 的新手,但我以前有 PHP 和 C# (OOP) 的编程经验。我所拥有的是:两个类,其中一个具有另一个类类型的私有(private)属性。来源:

class Foo
{
public:
Foo(int n)
{

}
};

class Bar
{
private:
Foo foo;

public:
Bar()
{
this->foo = Foo(10);
}
};

Bar bars[123];

我想做的是在 Bar 中使用构造函数声明 Foo 的属性。不幸的是,我这样做的方式不起作用。它给出了一系列错误,例如

no matching function for call to 'Foo::Foo()'

如何让它工作?感谢您的回复。

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