Xcode - 控制到达非 void 函数操作符错误的结尾
Xcode - Control reaches end of non-void function operator error
大家好,我在 Yosemite OS 上使用 Xcode,当我尝试使用这些运算符时出现错误 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());
} `//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
您没有 return 从声明为 return 值的函数中获取任何内容。例如:
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
}
您得到的特定错误 - "Control reaches end of non-void function" 只是意味着编译器遇到函数体的结尾而没有声明 return 是一个函数的值,其签名表明它应该是return 某事(错误消息的 "non-void" 部分)。
大家好,我在 Yosemite OS 上使用 Xcode,当我尝试使用这些运算符时出现错误 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());
} `//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
您没有 return 从声明为 return 值的函数中获取任何内容。例如:
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
}
您得到的特定错误 - "Control reaches end of non-void function" 只是意味着编译器遇到函数体的结尾而没有声明 return 是一个函数的值,其签名表明它应该是return 某事(错误消息的 "non-void" 部分)。