Xcode - 控制到达非无效函数运算符错误的末尾
Xcode - Control reaches end of non-void function operator error
大家好,我在优胜美地操作系统上使用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 函数的末尾"仅意味着编译器遇到函数体的末尾,而没有返回函数值的语句,该函数的签名指示它应该返回某些内容(错误消息的"非无效"部分)。
相关文章:
- 在运算符重载定义中使用成员函数(const错误)
- 逻辑运算符上出现错误代码 a')'
- 错误 C2679:二进制"<<":未找到采用类型 'std::string_view' 的右侧操作数的运算符(或者没有可接受的转换)
- C++:需要帮助了解运算符重载错误
- 我在 .h 中有一个枚举类,并且在.cpp错误中有一个运算符重载:与"运算符<<不匹配
- C++分数混合比较运算符错误
- 为什么我收到错误:"运算符<<不匹配?
- 迭代器类的重载前缀增量运算符会引发分段错误
- 在 boost::qi 中使用过多的替代运算符会导致分段错误
- 调用运算符时出现链接器错误<<,如何解决?
- 错误:表达式必须具有算术、无作用域枚举或带有运算符重载的指针类型
- 解决错误:运算符 [] 不匹配
- 提升错误:"运算符=="的重载不明确
- 字符串输入中没有匹配的错误运算符错误
- 错误:运算符 = IN C++ 不匹配
- QT 创建器错误(运算符 + 不匹配)
- 错误C++运算符重载
- 错误:运算符==不匹配
- C++ 语法和编译器错误 - 运算符不匹配<<
- C++错误--运算符=不匹配