包含for的函数没有内联展开

function containing for are not expanded inline

本文关键字:for 函数 包含      更新时间:2023-10-16

当我在Turbo c++编译器中运行这个c++代码时,它会给我以下错误:

  1. 第52行:包含for的函数不展开,内联
  2. 第74行:复合语句缺失
  3. 第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<&quot; "item deleted"<&quot; 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();
}