3
#include <vector>

int main()
{
    typedef const std::vector<const int> set_t;
    set_t Low = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};

    return 0;
}

When compiling the above code I got trillion of errors from STL headers.

What I want to do here is to initialize a vector and ensure that values can not be changed at some point later and also to make sure that no new values can be added.

This vector should be created once with initial values and not changed in any way.

What's wrong here?

2
  • 2
    const int is not a valid type. Elements need to be moved around. Commented Jul 9, 2014 at 2:37
  • if the size if fixed and known at compile-time, you can use std::array Commented Jul 9, 2014 at 2:43

1 Answer 1

3

This is also a const vector, and it will let your code compile.

typedef const std::vector<int> set_t;

Making the std::vector alone const will expose only the non-modifying interface. Your ints will not change.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.