Search code examples
c++c++11assigng++4.8stdarray

std::array error: Has no member named 'assign'


In the following code, the compiler complains as: struct std::array<double,5ul> has no member named 'assign'. Here, it seems possible. Why is it so? (Compiler: g++ 4.8.2)

#include <array>

int main()
{
    std::array<double,5> arr;
    arr.assign(4.); // error: has no member named 'assign'
    return 0;
}

Solution

  • That is very simple, as you can see here there is no assign member function for an std array. There is however a member function called fill you should be able to use.