0
菜鸟在这里,遗憾的错误填写标题3错误:错误:'Entry'未在此范围内声明。错误:模板参数1无效。错误:无效的类型在之前的声明“(”令牌
我试图编译从Bjarne的Stroustrup的“C++编程语言”这个代码段,但代码块不断抛出。我这个错误
的代码是关于检查范围的向量函数举行数组
#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 vector<T>::at(i); }
const T& operator[] (int i) const {return vector<T>::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); //this line is giving me trouble
int main()
{
return 0;
}
它给我的这些错误:
- 错误:'Entry'未在此范围内声明。
- 错误:模板参数1无效。
- 错误:??无效的类型在之前的声明“(”令牌
什么我不得不改变我如何申报VEC进入
您尚未申报Entry。 Entry是您传递给Vec模板类的类型。它可能是一个结构体或类,但是它没有在代码中的任何地方定义过,所以你不能使用它。 – Prismatic 2015-04-01 15:00:03
'Entry'似乎是本示例之前的几页。 – chris 2015-04-01 15:00:43
也没有Vec构造函数,它需要一个整数。 –
Prismatic
2015-04-01 15:02:08