A
A
Andrey PINEAPPLE2016-01-30 17:24:12
C++ / C#
Andrey PINEAPPLE, 2016-01-30 17:24:12

Is it possible to declare an int array using shared_ptr?

Does it make sense to declare an int array with a shared_ptr?
And if yes, then how to do it? And how to access such an array?
shared_ptr<int> sh(new int[100]);???
ps in general, there is a feeling that I'm not childishly stupid =)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vitaly, 2016-01-30
@AndreyHudz90

Yes.
How to handle... Dereference and access by index. Just why.

D
Dmitry, 2016-01-30
@EvilsInterrupt

Maybe std::array?
>>shared_ptr sh(new int[100]);
1. You say that you will store 1 int
2. You create 100 ints
3. And the result of step 2. you assign in item 1 though told that you will store one int
Cool?

P
Peter, 2016-01-30
@petermzg

You can see how the destructor is implemented in shared_ptr .
If it deletes the stored object through delete[] obj;, then you can use it,
but if delete obj;it doesn’t.
So rather NO.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question