错误:"*"的操作数必须是指针
Error: operand of '*' must be a pointer
我似乎在我的代码中遇到了这个错误,当我将鼠标悬停在说"数据"的位上时,它说"错误:"*"的操作数必须是一个指针"。谁能看出问题出在哪里。
double* Matrix::get(int i, int j) const
{
return *data[i*N + j];
}
假设data
是一个数组成员变量,你需要说的是:
return &data[i*N + j];
此外,由于您的函数const
您应该返回一个 const 指针:
const double *Matrix::get(int i, int j) const
{
return &data[i*N + j];
}
如果您不希望调用方修改数组中的值,请将其更改为:
double Matrix::get(int i, int j) const
{
return data[i*N + j];
}
如果 data
是 double 数组,则删除 *
,因为您不需要返回内存地址:
double Matrix::get(int i, int j) const
{
return data[i*N + j];
}
相关文章:
- 为什么我在空指针错误(链表)中获取成员访问权限
- std::函数指针错误:无法将 &A::a 转换为类型 std::function<>&&
- 为什么我得到 munmap_chunk():无效的指针:错误
- 成员模板函数指针错误
- 删除指针时,未分配被释放的 C++ 指针错误
- Visual Studio 中的"指向引用的指针"错误不会按发生位置的文件名显示
- C++数组指针错误无法将“int*”转换为“int**”
- C++ 通过函数指针错误调用成员函数
- 从 BST 中删除元素(指针错误)
- 随机生成的多维布尔指针错误
- 在测试中使用unique_ptr时指针错误无效
- 使用 malloc 而不是 new 会导致 free():指针错误无效
- 非标准语法;使用 '&' 创建指向成员的指针错误,将成员函数分配给向量时出错
- 抽象类和唯一指针 c++ 错误
- 返回函数指针错误而不带类型定义
- 练习中出现空指针错误
- 指针错误导致的分段错误(简单..)
- free():C++中的指针错误无效
- 使用布尔值数组"表达式必须具有指向对象类型的指针"错误C++
- 指针错误的C 数组