+ 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.

15th Nov 2019, 11:03 PM
Nick Original
Nick Original - avatar
10 odpowiedzi
+ 1
The function setColor(...) must be return by reference on object, i.e. : Class & setcolor(...) { ... return *this; }
16th Nov 2019, 5:20 AM
stamb
stamb - avatar
+ 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..
17th Nov 2019, 12:59 PM
Shubham
Shubham - avatar
+ 1
Shubham, one thing, what type of Setcolour(...) ?
18th Nov 2019, 1:52 AM
stamb
stamb - avatar
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...
15th Nov 2019, 11:12 PM
Nick Original
Nick Original - avatar
0
stamb why??
16th Nov 2019, 10:24 AM
Nick Original
Nick Original - avatar
0
What why? Your program ok?
16th Nov 2019, 11:49 AM
stamb
stamb - avatar
0
Void setcolour(char colour[]) This member function will return void type. It will just change the colour property of ball object.
18th Nov 2019, 4:46 AM
Shubham
Shubham - avatar
18th Nov 2019, 10:32 AM
stamb
stamb - avatar