Search code examples
c++staticconstantsprivate-members

static const std::vector


I am writing an image viewer with Qt. I am trying to do the following in the header file:

class ImageModel
{


private:
    const static std::vector<int> mZoomLevels;

}

in the source file:

int zooms[] = {1,2,3,4,5,6,7,8,9,10};
const std::vector<int> mZoomLevels(zooms.begin(),zooms.end());

However I get the following error:

request for member 'begin' in zooms which is of non-class type 'int[10]' request for member 'end' in zooms which is of non-class type 'int[10]'

Does anyone know how to initialize this static const private member ?


Solution

  • Plain arrays do not have member functions. I believe you're looking for this:

    int zooms[] = {1,2,3,4,5,6,7,8,9,10};
    const std::vector ImageModel::mZoomLevels(zooms, zooms + 10);