Noob here,
I'm trying to compile this segment of code from Bjarne Stroustrup's 'The C++ Programming Language' but CodeBlocks keeps throwing me this error.
The code is about range checking an array held in a vector function.
Here is the code:
#include <iostream>
#include <vector>
#include <array>
using namespace std;
int i = 1000;
template<class T> class Vec : public vector<T>
{
public:
Vec() : vector<T>() { }
T& operator[] (int i) {return at(i); }
const T& operator[] (int i) const {return at(i); }
//The at() operation is a vector subscript operation
//that throws an exception of type out_of_range
//if its argument is out of the vector's range.
};
Vec<Entry> phone_book(1000);
int main()
{
return 0;
}
The errors returned are:
- there are no arguments to 'at' that depend on a template parameter, so a declaration of 'at' must be available
- note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated
- In member function 'const T& operator[] (int i) const':
- there are no arguments to 'at' that depend on a template parameter, so a declaration of 'at' must be available
- 'Entry' was not declared in this scope
- template argument 1 is invalid
- invalid type in declaration before '(' token
Can someone explain this to me?
Also, how would I implement this if I were to not use 'using namespace std;'