相关疑难解决方法(0)

错误:"at"没有依赖于模板参数的参数,因此at的声明必须可用

Noob在这里,

我正在尝试从Bjarne Stroustrup的'The C++ Programming Language'编译这段代码,但CodeBlocks一直在向我抛出这个错误.

代码是关于范围检查向量函数中保存的数组.

这是代码:

#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() …
Run Code Online (Sandbox Code Playgroud)

c++ templates compiler-errors vector std

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

c++ ×1

compiler-errors ×1

std ×1

templates ×1

vector ×1