+ 1
Get and set
How can I do something like this : box.getContent().setColour("something"); Where box.getContent() returns an object that has method setColour(blabla) Because when I do it the setter doesn't work. I have tried everything... Please help me.
8 Respostas
+ 1
The function setColor(...) must be return by reference on object,
i.e. :
Class & setcolor(...) { ... return *this; }
+ 1
Make a class ball
Define method setcolour() in it .
Then make class box
And declare data member as object of class ball.
It will look like this....
Class ball
{
Private:
Char colour[8];
Public:
Setcolour( char[] colour_name)
{
Colour=colour_name;
}
}
Make class box...
Class box
{
Public:
Ball b;
Private:
Ball getContent()
{
Return a;
}
}
If you don't get it share me your code.. we will solve it..
+ 1
Shubham, one thing, what type of Setcolour(...) ?
0
Yes I have classes. But it doesn't work. The idea is that I have boxes and balls. The balls can be inside the boxes. I want to change the colour of some balls in the box but it doesn't work the way I wrote it...
0
stamb why??
0
What why? Your program ok?
0
Void setcolour(char colour[])
This member function will return void type.
It will just change the colour property of ball object.
0
One more, see the :
https://code.sololearn.com/cT5Zn25l8lmj/?ref=app