Search code examples
linuxboostshared-ptr

Boost smart array is not working


I have a code which compiles properly with Boost 1.49. i upgraded boost to 1.61 and now i am facing error like:

error: no matching function for call to boost::shared_array::shared_array(unsigned char) Boost/boost/smart_ptr/shared_array.hpp:56: note: candidates are: boost::shared_array::shared_array() [with T = unsigned char] Boost/boost/smart_ptr/shared_array.hpp:45: note: boost::shared_array::shared_array(const boost::shared_array&)

Code snippate is like

boost::shared_array<uint8_t> val;
constructor():val(0){}

what might be the possible solution for this?

My current set up is on a linux machine with GCC version 4.1.


Solution

  • You need to upgrade compilers. 4.1 is not supported by any recent version of boost.

    The snippet is no problem on supported combinations:

    Live On Coliru

    #include <boost/smart_ptr/shared_array.hpp>
    
    struct x {
        boost::shared_array<uint8_t> val;
        x() : val(0) {}
    };
    
    int main() {
        x x;
    }
    

    From the supported compilers page:

    Linux. GCC 4.5 and newer. Older versions may work too, but it was not tested.

    And

    The following compilers/platforms are not supported and will likely fail to compile the library:

    ...

    • GCC 4.2 and older.