Xcode - 控制到达非无效函数运算符错误的末尾

Xcode - Control reaches end of non-void function operator error

本文关键字:错误 运算符 函数 无效 控制 Xcode      更新时间:2023-10-16

大家好,我在优胜美地操作系统上使用Xcode,当我尝试使用这些运算符时,我遇到了错误 控制达到非无效功能的末尾,有人可以告诉我如何解决它吗?

`A& A::operator= (A& src)`
{
    delete[] b_;
    i_ = src.i_;
    b_ = new B[i_];
    for(int i = 0; i < i_; i++)
        b_[i].set(src.b_[i].get());
} `//Here appear this error>> Control reaches end of non-void function`

    std::ostream& operator<< (std::ostream& str, const A& a)
 {
     str << a.i_ << ":";
        for(int i = 0; i < a.i_; ++i)
            str << " " << a.b_[i].get();``
        return str << std::endl;
}
std::istream& operator>> (std::istream& str, A &a)
{
    int i;
    str >> i;
    A* b = new A(i);
    a = *b;
} //Here appear this error>> Control reaches end of non-void function

您不会从声明为返回值的函数返回任何内容。 例如:

A& A::operator= (A& src)`
{
    delete[] b_;
    i_ = src.i_;
    b_ = new B[i_];
    for(int i = 0; i < i_; i++)
        b_[i].set(src.b_[i].get());
  return *this;  // <-- return something
}
std::istream& operator>> (std::istream& str, A &a)
{
    int i;
    str >> i;
    A* b = new A(i);
    a = *b;
  return str;  // <-- return something
} 

您得到的特定错误 - "控件到达非 void 函数的末尾"仅意味着编译器遇到函数体的末尾,而没有返回函数值的语句,该函数的签名指示它应该返回某些内容(错误消息的"非无效"部分)。