I'm new to C++, but I have previous programming experience in PHP and C# (OOP). What I have is: two classes one of which has a private property with the type of the other class. Source:
class Foo
{
public:
Foo(int n)
{
}
};
class Bar
{
private:
Foo foo;
public:
Bar()
{
this->foo = Foo(10);
}
};
Bar bars[123];
What I'm trying to do is declare a property of Foo
with a constructor in Bar
. Unfortunately, the way I did it doesn't work. It gives a series of errors e.g.
no matching function for call to 'Foo::Foo()'
How do I get it working? Thanks for your reply.