Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
控件可能到达非无效函数Xcode c++;_Xcode_Queue - Fatal编程技术网

控件可能到达非无效函数Xcode c++;

控件可能到达非无效函数Xcode c++;,xcode,queue,Xcode,Queue,为什么我会犯这个错误?? 在我将这个文件添加到Xcode之前,这并不是一个错误,我不确定出了什么问题。 在“删除”函数的“我的队列”类中: class queue { private: point* Q[MSIZE]; int front, rear, size; public: queue() { // initialize an empty queue front = 0; rear = 0; size = 0;

为什么我会犯这个错误?? 在我将这个文件添加到Xcode之前,这并不是一个错误,我不确定出了什么问题。 在“删除”函数的“我的队列”类中:

class queue {

private:
    point* Q[MSIZE];

    int front, rear, size;

public:
    queue() {
        // initialize an empty queue
        front = 0; rear = 0; size = 0;
        for (int j=0; j < MSIZE; ++j)
           Q[j] = 0;
    }

    void insert(point* x) {
        if (size != MSIZE) {
            front++; size++;
            if (front == MSIZE) front = 0;
            Q[front] = x;
        }
    }

    point del() {
        if (size != 0) {
            rear++; if (rear == MSIZE) rear = 0;
            point temp(Q[rear]->getx(), Q[rear]->gety());
            size--;
            return temp;
        };
    } // error "Control may reach end of non-void function" on this line
}
类队列{
私人:
点*Q[MSIZE];
内景前,后,尺寸;
公众:
队列(){
//初始化空队列
前部=0;后部=0;尺寸=0;
对于(int j=0;jgetx(),Q[rear]->gety());
大小--;
返回温度;
};
}//此行出现错误“控件可能到达非无效函数的末尾”
}

函数
del
返回一个
。如果是尺寸!=0,没有返回语句。在另一种情况下,您需要返回一些内容,否则函数可以在不返回点的情况下结束,这将生成错误

由于无法执行
返回null
操作,因此解决此问题的一种方法是:

bool del(point& pointRef)
{
    if (size != 0)
    {
        rear++;
        if (rear == MSIZE)
        {
            rear = 0;
        }
        pointRef = Q[rear];
        size--;
        return true;
    }
    return false;
}
在这个函数之外,如果你得到了false,你就知道什么也没发生。如果为true,则您知道您有一个指向已删除
点的指针

调用它的示例:

point aPoint;
bool result;

result = del(aPoint);
if(result)
{
    // do stuff with aPoint
}
else
{
    // the queue was empty
}

我尝试了这一点,它给了我一个错误:“没有从'long'到'point'的可行转换”,返回NULLDoes
returnnil工作?我现在不在Xcode,所以我不能检查这个。你确定你是C++的吗?代码将在.mm文件中。哦,不能在C++中返回null。我会修正我的答案。请稍等。当我调用这个函数时,我想访问这个点并查看它的邻居。布尔值不允许我这样做查找传递引用的作用。您给此函数一个对
点的引用
,然后
bool
会告诉您该点是否有效。我们通过参数将
点返回给函数。