Home » U++ Library support » U++ Core » Error in "NTL - moveable" documentation?
Error in "NTL - moveable" documentation? [message #4249] |
Sun, 30 July 2006 11:00  |
Werner
Messages: 234 Registered: May 2006 Location: Cologne / Germany
|
Experienced Member |
|
|
Unless I'm very much mistaken the SimpleVector template in "Browse topics - srcdoc - Core" cannot work:
When you instantiate the class the constructor sets capacity and items = 0.
When you add an item items is >= 0 and Expand is called.
Expand doubles capacity, but 2 * 0 still yields 0.
So capacity can never grow.
Although the example demonstrates what it is supposed to demonstrate, in my personal opinion it should be faultless - be it just for didactic reasons.
One possible solution might be:
void Expand()
{
if (capacity == 0)
++capacity;
else
capacity *= 2;
...
Werner
[Updated on: Sun, 30 July 2006 11:04] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Mon Apr 28 16:41:01 CEST 2025
Total time taken to generate the page: 0.00921 seconds
|