错误:“calloc”未在此范围内声明
error: ‘calloc’ was not declared in this scope
我正在使用g++
编译我的代码arch linux
编译时收到此错误。 .error: ‘calloc’ was not declared in this scope
我没有尝试用ubuntu
编译这段代码,但我很确定它会通过。那么这是与arch linux
有关的问题还是我的代码出了问题
这是我的代码:
#include <cstdio>
using namespace std;
class Graph
{
private :
unsigned int numNodes;
class Connection
{
public :
int to;
int weight;
Connection (int to,int weight)
{
this->to = to;
this->weight = weight;
}
Connection (int to)
{
this->to = to;
}
};
Connection **nodeList;
public :
Graph (unsigned int numNodes)
{
this->nodeList = calloc (sizeof (Connection*),numNodes);
this->numNodes = numNodes;
}
};
std::calloc
函数在<cstdlib>
中定义。您需要包含它才能修复此错误。
话虽如此,您最好使用 operator new
- 一种在C++中分配动态内存的惯用方法。
而且使用std::vector
而不是使用原始指针和new
会更好(更好)。
相关文章:
- 错误:未在此范围内声明'reverse'
- 错误:"imread"未在此范围内声明
- 未在此范围内声明错误 'xy'
- Socklen_t未在此范围内声明
- 错误:'[' 之前预期的非限定 id 和错误:'users'未在此范围内声明
- "Main"已在当前范围内声明
- c++ 变量在宏的扩展中没有在这个范围内声明
- C++ 在编译过程中 strtok 函数 Eclipse 说没有在范围内声明?
- 'num1'未在此范围内声明
- 如何找到在本地范围内声明的变量的地址?
- NT状态未在此范围内声明
- 变量未在此范围内声明 数组线性搜索
- 包含文件中的 Typdef "未在此范围内声明"
- 'ClassName'和'ClassInstance'未在此范围内声明
- C++ 中的类之间的数据重新循环 - 错误:'<class name>'未在此范围内声明
- 代码作为 C 文件工作,但不作为C++文件,错误:'__builtin_types_compatible_p'未在此范围内声明
- 如何修复错误:"vreinterpretq_u32_f64"未在此范围内声明 - 在Android上使用Eigen构建
- 如何修复C++中的"arrStud未在此范围内声明"错误
- 错误:"SHGetKnownFolderPath"未在此范围内声明
- 错误:'Sprite'未在此范围内声明