Re: Problem with composition
Quote:
Originally Posted by
depecheSoul
int main()
{
addition add(numbers);
cout<<add.rezultat()<<endl;
}
The bold line declares a function called 'add' that takes a numbers object as argument and returns an addition object. If you want to create a variable called add of type addition that is instantiated with a default constructed numbers object, I think you can do this:
Code:
int main()
{
addition add(numbers());
}
That said, I don't see the point of having a class that can only contain undefined values.
Re: Problem with composition
The problem is that this declares a function named add that has a parameter of type numbers and returns an addition object:
Code:
addition add(numbers);
You should create a numbers object to pass to the constructor of the addition object named add. Furthermore, note that numbers does not have an appropriate constructor, for now.
Re: Problem with composition
What D_Drmmr said
Quote:
Originally Posted by
D_Drmmr
I think you can do this:
Code:
int main()
{
addition add(numbers());
}
Actually, that doesn't work either. You'd have to add an extra set of parenthesis:
Code:
int main()
{
addition add((numbers()));
cout<<add.rezultat()<<endl;
}
That said, I think you'd be better off with either a default parameter, or a named dummy:
Code:
int main()
{
numbers aNumber;
addition add(aNumber);
cout<<add.rezultat()<<endl;
}
Re: Problem with composition
Quote:
Originally Posted by
monarch_dodra
What D_Drmmr said
Actually, that doesn't work either. You'd have to add an extra set of parenthesis:
Yeah, that's what I was afraid of. Thanks for clearing it up.
Re: Problem with composition
Thank you very much it worked with double ()