Imitating a vector's constructor?

.......
Last edited on
In ReadChain(), where are you allocating an array of the size the user entered?

Instantiating a (main #1) allocates a single object. Any attempt to reference an element other than [0] will result in a crash.

In chain.h, line 7, why are you setting size_ to 1 only if value is non-zero? You've allocated one element. Shouldn't size_ be 1 unconditionally? The size of the array and the value with which you initialize it are unrelated.


Last edited on
Thanks for replying.

I'm just a little confused in regards to instances where I'm simply declaring a new blank Chain, like Chain<int>a. How can I write it so that if the chain isn't instantiated with a value (like Chain<int> z{4}), the size is 0?
How can I write it so that if the chain isn't instantiated with a value (like Chain<int> z{4}), the size is 0?

You've already done this with the default argument value.

If you think that line 16 somehow extends the size of your dynamically allocated array automatically, it does not.
Topic archived. No new replies allowed.