不明白这个错误:初始化"类"的参数 1 [使用 T = 无符号 int]' [-允许]
Don't understand this error: initializing argument 1 of 'class' [with T = unsigned int]' [-fpermissive]
这是我在 Eclipse 中构建时出现的 3 个错误中的第一个。
在 main 函数中,我只是实例化类 multidimensional_vector<1,无符号 int>这是一个模板。
奇怪的是,当我将第 14 行 push_back() 中的参数 w 更改为 *w 时,错误消失了。但我刚刚读到push_back指针是不行的,所以我想知道是否可以使用 *w 作为 push_back() 的参数?
代码:
#include <vector>
#include <stdlib.h>
using std::vector;
enum Foo { length = 4, heigth = 4};
template<unsigned int dimcount, typename T>
class multidimensional_vector
{
private: vector< multidimensional_vector<dimcount-1, T> > wector;
public:
multidimensional_vector() {}
multidimensional_vector(T a) {
for (int var = 0; var <= heigth; ++var) {
multidimensional_vector<dimcount-1, T> *w = new multidimensional_vector<dimcount-1, T>(a);
wector.push_back(w);
}
}
T getValue(vector<unsigned int> v){
return wector[v[dimcount]].getValue(v);
}
void setValue(vector<unsigned int> v, T value){
wector[v[dimcount]].setValue(v, value);
}
};
template<typename T>
class multidimensional_vector<0,T>
{
private: T value;
public:
multidimensional_vector() {}
multidimensional_vector(T a) {
value = a;
}
T getValue(vector<unsigned int> v){
return value;
}
void setValue(vector<unsigned int> v, T value){
this->value = value;
}
};
int main() {
multidimensional_vector<1, unsigned int> *nimarray = new multidimensional_vector<1, unsigned int>(0);
return 0;
}
当尝试从问题中编译代码片段时,gcc 5.3.1 报告的唯一错误是:
t.C:12:34: error: ‘heigth’ was not declared in this scope
for (int var = 0; var <= heigth; ++var) {
GCC 不会报告您询问的任何错误。
手动将此变量的声明添加到类后,给定的代码编译没有任何问题。
除了缺少类成员声明之外,给定的代码绝对没有问题。
相关文章:
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 将无符号char*转换为std::istream*C++
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- 从矢量<无符号字符>转换为字符* 包括垃圾数据
- 如何理解将半精度指针转换为无符号长指针和相关的内存对齐
- C++中无符号字符溢出
- 使用无符号字符数组有效存储内存
- 如何打印boost多精度128位无符号整数
- C++模板函数,用于比较任何无符号整数和有符号整数
- 在 std::无符号字符的向量处存储 int 的十六进制表示形式
- 获取隐式转换溢出从无符号到已签名的警告
- 如何在保持其值的同时将 c++ 无符号字符变量转换为 char 变量
- 从 std::vector<无符号字符>切片中提取 int?
- 是什么导致了这种使用三进制而不是短整型的有符号int到无符号int转换
- 无法在 Arduino 中uint8_t数组转换为无符号长整型数组
- 将无符号字符的向量存储在数组中会给我 std::bad_alloc
- 使用 fopen 打开 .pak 文件并使该文件应用于 const 无符号字符* (C++)
- 是否允许将字符 [] 转换为无符号字符 *
- 不允许从"常量无符号字符*常量*"到"常量字符*常量*"static_cast
- 不明白这个错误:初始化"类"的参数 1 [使用 T = 无符号 int]' [-允许]