包含for的函数没有内联展开
function containing for are not expanded inline
当我在Turbo c++编译器中运行这个c++代码时,它会给我以下错误:
- 第52行:包含for的函数不展开,内联
- 第74行:复合语句缺失
- 第74行:声明不正确终止。
#include
#include
#define MAXSIZE 10
#include
class queue
{
int s[MAXSIZE],front,rear,i;
public:
queue(){front=-1;rear=-1;}
void insert(int val)
if(rear==MAXSIZE-1)
cout<<";
else
if(front==-1)
{
front=0;
}
后=后+ 1;
cout<& lt;" n"& lt; & lt;"输入信息"
cin>>s[val];
}
void del()
{
if(front==-1)
cout<<"queue is empty";;
else
cout<" "item deleted"<" s[front];
if(front==-1)
front=rear=-1;
}
void traverse ()
{
if(front==-1)
cout"queue is empty";
cout"其他
{
(i =面前;i<=后面;我+ +)
cout<& lt;" t"& lt; & lt; s[我];
{
}
};
void main ()
{
linklist l1;
l1.insert (10);
l1.insert (20);
l1.insert (30),
l1.traverse ();
l1.del ();
l1.insert (40);
getch ();
}
这应该可以编译,但它不会像预期的那样工作。我不打算尝试修复它,因为逻辑太坏了,在继续之前阅读文本中的队列处理得更好。
我不能确定这在Turbo c++中编译。自90年代以来,我就没有使用过Turbo c++,即使在那时,我也只是用它来编译C代码。
注释中嵌入了解释,使所有内容都集中在一个块中。
#include<iostream> // don't need the .h
#include<conio.h>
#define MAXSIZE 10
#include<stdlib.h>
// need to specify namespaces. Don't pull in the whole namespace unless you
// know exactly what you are doing. JUst use the parts you need or explicitly
// state with every use eg. std::cout << "queue is full";
using std::cout;
using std::cin;
using std::endl;
class queue
{
int s[MAXSIZE], front, rear; // no need to define i here. Only used in
// the traverse method and has no need for
// persistence
public:
queue()
{
front = -1;
rear = -1;
}
void insert(int val)
{ // this function almost certainly does not work logically
// a queue adds to one end and takes from the other. This allows the
// caller to put an element anywhere in the queue, destroying
// whatever value was in that slot.
if (rear == MAXSIZE - 1)
{ // always use all of the braces while learning. You can take the
// training wheels off when you know how to do it safely.
cout << "queue is full";
}
else if (front == -1)
{
front = 0;
}
rear = rear + 1;
cout << "n" << " Enter the info";
// using n in place of std::endl may have unexpected consequences
// with respect to flushing. std:: endl means end the line and write the
// output. In this case,display on the console. n means end the line and
// write when you feel like it. Result is the user prompt may not be
// written before it stops for user input on the next line.
cin >> s[val];
}
void del()
{ // this function's logic is also broken.
if (front == -1)
{
cout << "queue is empty";
}
else
{
cout << "item deleted" << s[front];
}
if (front == rear)
{
front = rear = -1;
}
else
{
front = front + 1;
}
}
void traverse()
{
if (front == -1)
{
cout << "queue is empty"; // missed the <<. This broke the for loop
// because the braces weren't used and
// the compiler choked rather than giving
// a reasonable error message.
}
else
{
for (int i = front; i <= rear; i++) // defined the i removed earlier
{
cout << "t" << s[i];
}
// braces here were completely messed up.
}
}
};
void main()
{
queue l1; // was linklist rather than queue
l1.insert(10);
l1.insert(20);
l1.insert(30);
l1.traverse();
l1.del();
l1.insert(40);
getch();
}
相关文章:
- "error: no matching function for call to"构造函数错误
- 当 A 在 for 循环中调用函数 B 时,如何计算函数 A 的空间复杂度?
- C++函数模板需要 &for 数组参数
- 有没有办法将 for 循环结果返回到像三元运算符这样的函数中?
- 创建函数变体向量时"No matching function for call"错误
- 如果子类中没有构造函数方法,则错误"no matching function for call to 'LGame::LGame(String&)'"
- 虚拟函数调用的性能作为 for 循环中的上限
- constexpr 函数中的 for 循环无法使用 MSVC 19.23 进行编译
- 函数中的"pragma omp parallel for"在另一个并行循环中调用函数时无效
- 找不到如何创建使用指针、字符和 for 函数组合的程序
- 这个基于范围的'for'语句需要一个合适的函数,但找不到任何函数
- For 和 while 循环在全局定义的函数中不起作用
- c++ 中的 range-for 会调用项的复制构造函数吗?
- C++ - 计算"for"函数中的平均值
- 在包含 R/Cpp 代码的 R 包中使用 roxygen2 for R 函数
- 使用 for 函数时结构上的二进制"["错误
- 使用 decltype for 函数生成的非类型模板参数
- OpenMPI for C++:函数内部的排名变化显然是无缘无故的
- 调用for函数,只返回0
- 是否可以使用using for函数