我一直得到一个期望;错误,我不确定为什么
i keep getting an expected ; error and i'm not sure as to why
我写完了代码,但无法弄清楚为什么我得到预期的;错误
我尝试添加 ; 它也期望我,但它会回击其他错误
这是我的代码
int main() {
int* expandArray(int *arr, int SIZE) { //this is the error line
//dynamically allocate an array twice the size
int *expPtr = new int[2 * SIZE];
//initialize elements of new array
for (int i = 0; i < 2 * SIZE; i++) {
//first add elements of old array
if (i < SIZE) {
*(expPtr + i) = *(arr + i);
}
//all next elements should be 0
else {
*(expPtr + i) = 0;
}
}
return expPtr;
}
}
C++不允许
嵌套函数。你不能在 main(( 中定义函数。
事实上,这是我们可以在C++函数内有函数吗?
您可能希望:
int* expandArray(int *arr, int SIZE)
{ //this is the error line
//dynamically allocate an array twice the size
int *expPtr = new int[2 * SIZE];
//initialize elements of new array
for (int i = 0; i < 2 * SIZE; i++)
{
//first add elements of old array
if (i < SIZE)
{
*(expPtr + i) = *(arr + i);
}
//all next elements should be 0
else
{
*(expPtr + i) = 0;
}
}
return expPtr;
}
int main()
{
// call expandArray here
}
相关文章:
- 提升精神 x3 错误处理程序与期望
- 我一直得到一个期望;错误,我不确定为什么
- 使用 gtest EXPECT_CALL 时竞争条件段错误,而另一个期望是执行相同的方法
- Variadic模板:候选人期望1个参数,0提供(扣除错误)
- 我有 3 个错误:期望一个")",期望一个表达式,long 类型的参数与 U32 类型的参数不兼容
- 错误:“;期望的类名”;
- 错误C2057:期望的常量表达式
- 错误:')'令牌强制转换问题之前期望的主表达式
- Boost Python运行时错误,将派生类型的对象从Python传递给c++函数,期望将shared_ptr传递给基类
- 语法错误,意外的标记,期望文件结束
- 错误:当通过P2P通道连接两个NodeContainers时,期望主表达式在ns3中的const之前
- 错误:':'令牌之前期望的初始化项
- c++ -错误:在'{'标记之前期望的类名
- 错误:期望声明
- 试图为继承类的子类编写构造函数,猜测语法,期望的主表达式错误
- if语句中的函数:期望的错误表达式
- 编译错误:solution.c:20:5: Error:期望的标识符或'('在' {' token{之前
- QT 5.2.1编译错误;在'delete'之前期望的非限定id
- 程序没有给出期望的输出.FIFO的错误实现
- 编译时错误:期望的构造函数、析构函数或转换