Re: Assigning values to a struct
Cliff wrote:
On Aug 29, 12:59 am, "Alf P. Steinbach" <al...@start.no> wrote:
Try
BoxColor const color = { 10, 20, 30 };
Cheers, & hth.,
- Alf
Hi Alf,
Sorry, I should have said, a single instance of this TBoxColour gets
assigned new values in 100's of locations throughout the code.
I suppose the only way is:
Col.Red = 10;
Col.Green = 20;
Col.Blue = 30;
The original method looks more elegant, This is just ugly, but more
importantly it's not easy for me to change the code with a simple
search and replace.
You can define a function (a pseudo-constructor):
BoxColor createBoxColor(int a, int b, int c) {
BoxColor bc = { a, b, c };
return bc;
}
and then use it anywhere you need to assign:
Col = createBoxColor(10, 20, 30);
(I understand that I barge in without reading the rest of the thread,
sorry for that; if what I wrote is bogus, forgive me and ignore it)
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask