As many people have I am reading Mr Stroustrup's book Programming Principles and Practices. All was fine till I got to the Graphics chapters.

I have installed fltk and it works fine. My problem is when I try to use the books graphics libraries. Window.h produces a "Vector is not a member of std:" compiler error.

The std_lib_facilities.h file that these libraries use has the line #define vector Vector that the comments say is there to get a range checked vector. This is not required because VS 2017 range checks vectors during a debug build anyway.

I have tried commenting out the #def but that just generates more errors. I am stuck. Has anyone else been able to make this work ?

1 Answers

Gox On

:) I have just gone through PPP. And couple of times I had the same problem. If you look into std_lib_facilites.h he overrode the vector class:

Here it is:

// trivially range-checked vector (no iterator checking):
template< class T> struct Vector : public std::vector<T> {                                                                                                    
    using size_type = typename std::vector<T>::size_type;

#ifdef _MSC_VER
    // microsoft doesn't yet support C++11 inheriting constructors
    Vector() { }
    explicit Vector(size_type n) :std::vector<T>(n) {}
    Vector(size_type n, const T& v) :std::vector<T>(n,v) {}
    template <class I>
    Vector(I first, I last) : std::vector<T>(first, last) {}
    Vector(initializer_list<T> list) : std::vector<T>(list) {}
    using std::vector<T>::vector;   // inheriting constructor

    T& operator[](unsigned int i) // rather than return at(i);
        if (i<0||this->size()<=i) throw Range_error(i);
        return std::vector<T>::operator[](i);
    const T& operator[](unsigned int i) const
        if (i<0||this->size()<=i) throw Range_error(i);
        return std::vector<T>::operator[](i);

// disgusting macro hack to get a range checked vector:
#define vector Vector 

So your solution is to not include std_lib_facilities.h, or to use his vector class, or you can delete this line:

#define vector Vector