na***********@gmail.com wrote:
When I compile, I get two error messages per member function I defined
in my class declaration. The first error states the function name and
says that it already has a body. While the second error message says
to see previous definition of the function.
Here is an example. These are my constructors declarations and their
corresponding function code:
card ();
card::card()
{
}
card (int face, char csuit);
card::card(int face, char csuit) : rank(face), suit(csuit)
{
}
I copied and pasted these directly from my file. Thanks.
Here is one way to do it (there are several ways)...
--- In the file card.hpp:
// definition of the class 'card' (no inline methods).
// this header (card.hpp) can be included by any source
// file (.hpp or .cpp) that needs to know about the
// 'card' class.
class card
{
public:
card();
card(int face, char csuit);
// declare any other public methods here...
private:
int rank;
char suit;
};
--- In the file card.cpp:
#include "card.hpp"
// implement the funtions of class 'card'...
card::card() : rank(0), suit(0)
{
// do any other constructor stuff here...
}
card::card(int face, char csuit) : rank(face), suit(csuit)
{
// do any other constructor stuff here...
}
// implementation of other 'card' methods here...
---
Which C++ tutorial book are your reading?
Regards,
Larry