Control reaches end of non-void function [-werror=return-type]error? How do I fix this? I've included my code below.
Question:
Control reaches end of non-void function [-werror=return-type]error? How do I fix this? I've included my code below. C++ code bythe way.
#include
#include
#include
#include
#include
#include "GroceryItem.hpp"
namespace
{
constexpr auto EPSILON = 1.0E-4;
}
GroceryItem::GroceryItem( const std::string &productName,
const std::string & brandName,
const std::string & upcCode,
double price )
: _upcCode (upcCode ),
_brandName (brandName ),
_productName (productName),
_price (price )
{}
std::string GroceryItem::upcCode() const
{ return _upcCode; }
std::string GroceryItem::brandName() const
{ return _brandName; }
std::string GroceryItem::productName() const
{ return _productName; }
double GroceryItem::price() const
{ return _price; }
void GroceryItem::upcCode( const std::string & upcCode )
{ _upcCode = upcCode; }
void GroceryItem::brandName( const std::string & brandName)
{ _brandName = brandName; }
void GroceryItem::productName( const std::string &productName )
{ _productName = productName; }
void GroceryItem::price( double price )
{ _price = price; }
std::istream & operator>>( std::istream & stream,GroceryItem & groceryItem )
{
GroceryItem workingItem;
char delimiter = ',';
stream >> std::quoted(workingItem._upcCode) >>delimiter
>> std::quoted(workingItem._brandName ) >>delimiter
>> std::quoted(workingItem._productName) >>delimiter
>> workingItem._price;
if(stream) groceryItem = std::move( workingItem );
return stream;
}
std::ostream & operator<<( std::ostream & stream,const GroceryItem & groceryItem )
{
const std::string delimiter = ", ";
stream << std::quoted( groceryItem.upcCode() ) <
<< std::quoted( groceryItem.brandName() ) <
<< std::quoted( groceryItem.productName() ) <
<< groceryItem.price();
return stream;
}
bool operator==( const GroceryItem & lhs, const GroceryItem& rhs )
{
if constexpr( (false) )
{
return !( lhs < rhs ) && !( rhs < lhs );
}
else
{
return lhs._upcCode == rhs._upcCode
&& lhs._brandName == rhs._brandName
&& lhs._productName == rhs._productName
&& std::abs(lhs._price - rhs._price) < EPSILON;
}
}
bool operator< ( const GroceryItem & lhs, constGroceryItem & rhs )
{
if( auto result = lhs._upcCode .compare( rhs._upcCode ); result!= 0)
if( auto result = lhs._brandName .compare( rhs._brandName );result != 0)
if( auto result = lhs._productName.compare( rhs._productName);result != 0)
if( std::abs( lhs._price - rhs._price ) >= EPSILON )
return false;
}
bool operator!=( const GroceryItem & lhs, const GroceryItem& rhs ) { return !( lhs == rhs ); }
bool operator<=( const GroceryItem & lhs, constGroceryItem & rhs ) { return !( rhs < lhs ); }
bool operator> ( const GroceryItem & lhs, constGroceryItem & rhs ) { return ( rhs < lhs ); }
bool operator>=( const GroceryItem & lhs, constGroceryItem & rhs ) { return !( lhs < rhs ); }
Sorry for not being entirely clear. I have recieved the error"control reaches end of non-void function [-Werror=return-type]"having to do within the fuction 'bool operator<(constGroceryItem&' . This is being compiled inside of a terminal.How can I fix this error? I've also included another picture alongwith my entire code above.
Once again, I apologize for not being clear. Below I have copyand pasted the code for the file GroceryItem.hpp
#pragma once // include guard
#include #include
class GroceryItem{ // Insertion and Extraction Operators friend std::ostream & operator<<( std::ostream& stream, const GroceryItem & groceryItem ); friend std::istream & operator>>( std::istream& stream, GroceryItem &groceryItem );
// Relational Operators friend bool operator==( const GroceryItem & lhs, constGroceryItem & rhs ); friend bool operator< ( const GroceryItem & lhs,const GroceryItem & rhs );
public: // Constructors GroceryItem() = default; GroceryItem( const std::string &productName, const std::string & brandName = {}, const std::string & upcCode = {}, double price = 0.0 );
// Queries std::string upcCode ()const; std::string brandName ()const; std::string productName () const; double price () const;
// Mutators void upcCode (const std::string & upcCode ); void brandName ( conststd::string & brandName ); void productName ( const std::string &productName ); voidprice (double price );
private: std::string _upcCode; std::string _brandName; std::string _productName; double _price =0.0;};
// Relational Operatorsbool operator==( const GroceryItem & lhs, const GroceryItem& rhs );bool operator!=( const GroceryItem & lhs, const GroceryItem& rhs );
bool operator< ( const GroceryItem & lhs, constGroceryItem & rhs );bool operator<=( const GroceryItem & lhs, const GroceryItem& rhs );bool operator> ( const GroceryItem & lhs, const GroceryItem& rhs );bool operator>=( const GroceryItem & lhs, const GroceryItem& rhs );
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill