boost::shared_array<char const *> x(new char const *[n]);
In the line above (n is integer number not greater than 100) I'm creating char const**(const char**) and putting it to smart pointer x for arrays to be deleted when x is deleted. And for me it is clearly how and why this work.
boost::shared_array<char const *> x = new char const *[n];
Now lets take a look to second line. Here in my opinion we do exactly the same as in first case. Yes at first glance we may seem that here we constructing x via NULL(default value of shared_array constructors parameter) then calling operator=, but this is mistake, and as I know in this case instead of operator= will be called constructor with pointer created by new opeartor.
But in spit of this I'm getting error C2440: 'initializing' : cannot convert from 'const char **' to 'boost::shared_array<T>
The only problem I see this is the explicit constructor of boost::shared_array<T>. But I don't know what is the problem? Why does explicit constructor cause this error? And if the problem is not in explicit constructor, then where, why?
Your guess is correct.
What you're trying to do in the second line is implicitly calling the constructor: you want the C++ compiler to realize that there is a constructor available that accepts a T* and use it. However, since the constructor is marked as explicit, it cannot be invoked this way.
See for example the discussion at http://www.go4expert.com/forums/showthread.php?t=20756.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With