473,386 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Error: function already has a body

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.

Apr 16 '06 #1
2 18080
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
Apr 17 '06 #2
In article <11*********************@g10g2000cwb.googlegroups. com>,
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.


I suspect you are including something more than once, or possibly
including a cpp file into another cpp file.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Apr 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bernhard Georg Enders | last post by:
Hi! Everything works fine with Opera and IE, but not with Mozilla 1.7.3 and Firefox 1.0 PR. When I call a function previously defined inside another function I've got "function is not defined"....
2
by: Simon Wigzell | last post by:
I have the following in my page body tag: <body onMouseMove="mouseCheck(event);"> The problem is that the mouseCheck function cannot be loaded until the entire page is loaded so you get an JS...
21
by: Karl O. Pinc | last post by:
FYI, It'd be nice if the error message from a REFERENCES constraint mentioned the column name into which the bad data was attempted to be inserted. In PostgreSQL 7.3: sandbox=> insert into...
0
by: Marcel Boscher | last post by:
Hello everybody, i get strange error messages when trying to call up my function with a SELECT functionname(with or without int); varying from: ERROR: function chr(double precision) does...
3
by: Rohini | last post by:
Hi , I am getting the following LINK 2005 error when I tried to build my project in vc++7.1. I am doing the build process in win32release mode. I have searched google on this but whatever I...
6
by: cyberco | last post by:
Using fileinput.input('test.txt') I probably forgot to process all lines or so, since I get the error 'input() already active' when i try to call fileinput.input('test.txt') again. But how can I...
1
by: jinendrashankar | last post by:
Hi All, 1.Please check this code and its output which is working fine while pure virtual functions( FUN1) prototype of Class CA is different then Class CB Function (FUN1). 2. In Class...
0
by: William LaMartin | last post by:
I have created a web service that simply uses WebClient to retrieve the text of a web page. If I access the asmx page with my browser and put in a URL, it retrieves the text of that page with no...
36
by: AB3004 | last post by:
Hi, I'm currently working on this piece of code & unfortunately, whenever I run it, it states that selectNumbers isn't defined and it errors on Line 1 (?) can anyone tell me why? I'm tearing my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.