I created a simple template. It gives me a warning: “No return, in function returning non-void”.
template<typename T> struct test {
public:
test & operator=(const T & new_value) {
value = new_value;
}
operator T() const {
return value;
}
private:
T value;
};
The warning is pointing at
test & operator=(const T & new_value) {
value = new_value;
}
Can anyone offer some advice on how to fix this warning.
As the warning rightly says, your function isn’t returning anything, even though it promises to return a
test &. Simply end your function withreturn *this;, as is the usual convention for assignment operators.