0

The combine function been bug since yesterday.

Been trying everything back then, define in the source file, remove some code to prevent overlapping definition, etc...
I don't know what I should do, can anyone help on this?

#ifndef SALES_DATA
#define SALES_DATA

#include <iostream>

struct Sales_data {
    // new members: operations on Sales_data objects
    std::string isbn() const { return bookNo; }
    double avg_price() const;
    Sales_data& combine(const Sales_data&);

    // data members are unchanged from
    std::string bookNo;
    unsigned units_sold;
    double revenue;
};

Sales_data& Sales_data::combine(const Sales_data &rhs)
{
    units_sold += rhs.units_sold;
    revenue += rhs.revenue;
    return *this;
}

std::istream &read(std::istream & is, Sales_data &item);
std::ostream &print(std::ostream &os, const Sales_data & item);
Sales_data add(const Sales_data &lhs, const Sales_data &rhs);

#endif
3
Contributors
4
Replies
19
Views
3 Years
Discussion Span
Last Post by Schol-R-LEA
Featured Replies
  • You can't put functions in header files -- move lines 18-21 into main.cpp or some other \*.cpp file. Read More

  • [This posting](http://forums.devshed.com/showpost.php?p=2001351&postcount=14) may help explain why it is (generally speaking) a mistake to include functions in a header, and what headers are mainly used for in the first place. Read More

0

what compiler and operating systems are you using? And post a few of the errors.

Why don't you just call it a class instead of struct because that's what it is. structs are carry-over from C language and normally do not contain methods. Although both structs and classes are nearly the same in C++ it is more conventional to call it a class when it contains methods.

Edited by Ancient Dragon

0

mingW and windows 7 ultimate 64bit

this is the error:
Click Here

This is the exercise coming from C++ primer 5th edi.
not learned about class yet.

Edited by Vasthor: ehem

1

This posting may help explain why it is (generally speaking) a mistake to include functions in a header, and what headers are mainly used for in the first place.

This article has been dead for over six months. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.