472,981 Members | 1,459 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Multiple definition error

Similar problem to the previous post. I have created a project with
about 7 files including 3 header files and 3 implementation files. I
am getting a multiple definition error when compiling for one specific
file of class. I have checked that if there is more than one
allocation of storage for identifiers, this error arises. But I don't
see where the problem lies. Any suggestions?

<code>
//ItemType.h
#ifndef ItemType_hpp // I was told to include this directives
#define ItemType_hpp

#include <fstream>
#include <iostream>
#include "StrTypeAugmented.h"

const int MAX_ITEMS = 25;

enum RelationType {LESS, EQUAL, GREATER};
class HouseType
{
public:
void GetFromFile(std::ifstream&);
void WriteToFile(std::ofstream&);
void GetFromUser();
void PrintHouseToScreen();
void GetNameFromUser();
void PrintNameToScreen();
RelationType ComparedTo(HouseType);

private:
StrType lastName;
StrType firstName;
StrType address;
float price;
int squareFeet;
int bedRooms;
};
#endif
// ItemType.cpp
#include "ItemType.h"

typedef HouseType ItemType;

using namespace std;
// ItemType.cpp is the implementation file for data for the real
// estate manipulation program.

void HouseType::GetFromFile(std::ifstream& file)
{
lastName.GetStringFile(true, NOT_NEW, file);
firstName.GetStringFile(true, NOT_NEW, file);
address.GetStringFile(true, NOT_NEW, file);
file >price >squareFeet >bedRooms;
}

void HouseType::WriteToFile(std::ofstream& file)
{

lastName.PrintToFile( false, file);
firstName.PrintToFile(true, file);
address.PrintToFile(true, file);
file << endl << price << endl;
file << squareFeet << endl;
file << bedRooms << endl;
}

void HouseType::GetFromUser()
{

cout << "Enter last name; press return." << endl;
lastName.GetString(true, NOT_NEW);
cout << "Enter first name; press return." << endl;
firstName.GetString(true, NOT_NEW);
cout << "Enter address; press return." << endl;
address.GetString(true, NOT_NEW);
cout << "Enter price, square feet, number of bedrooms;"
<< " press return." << endl;
cin >price >squareFeet >bedRooms;
}

void HouseType::PrintHouseToScreen()
{

firstName.PrintToScreen( false);
cout << " ";
lastName.PrintToScreen( false);
address.PrintToScreen(true);
cout << endl << "Price: " << price << endl;
cout << "Square Feet: " << squareFeet << endl;
cout << "Bedrooms: " << bedRooms << endl;
}

void HouseType::GetNameFromUser()
{

cout << "Enter last name; press return." << endl;
lastName.GetString(true, NOT_NEW);
cout << "Enter first name; press return." << endl;
firstName.GetString(true, NOT_NEW);
}

void HouseType::PrintNameToScreen()
{

firstName.PrintToScreen( false);
cout << " ";
lastName.PrintToScreen( false);
cout << endl;
}

RelationType HouseType::ComparedTo(HouseType house)
{
if (lastName < house.lastName)
return LESS;
else if (house.lastName < lastName)
return GREATER;
else if (firstName < house.firstName)
return LESS;
else if (house.firstName < firstName)
return GREATER;
else return EQUAL;
}

</code>
ERROR:
multiple definition of
`HouseType::GetFromFile(std::basic_ifstream<char,
std::char_traits<char&)'
first defined here
multiple definition of
`HouseType::WriteToFile(std::basic_ofstream<char,
std::char_traits<char&)'
etc..

Apr 11 '07 #1
10 2741
zf*****@mail.com wrote:

<snip>
ERROR:
multiple definition of
`HouseType::GetFromFile(std::basic_ifstream<char,
std::char_traits<char&)'
first defined here
multiple definition of
`HouseType::WriteToFile(std::basic_ofstream<char,
std::char_traits<char&)'
etc..
You must have the function defined in another source file.

--
Ian Collins.
Apr 11 '07 #2
Ian Collins wrote:
zf*****@mail.com wrote:

<snip>
>>ERROR:
multiple definition of
`HouseType::GetFromFile(std::basic_ifstream<char ,
std::char_traits<char&)'
first defined here
multiple definition of
`HouseType::WriteToFile(std::basic_ofstream<char ,
std::char_traits<char&)'
etc..

You must have the function defined in another source file.
Or are you linking the same source file twice?

--
Ian Collins.
Apr 11 '07 #3
basic rule: member function should be in implementation file or should
be static/inline(if in .h file)
zf*****@mail.com wrote:
Similar problem to the previous post. I have created a project with
about 7 files including 3 header files and 3 implementation files. I
am getting a multiple definition error when compiling for one specific
file of class. I have checked that if there is more than one
allocation of storage for identifiers, this error arises. But I don't
see where the problem lies. Any suggestions?

<code>
//ItemType.h
#ifndef ItemType_hpp // I was told to include this directives
#define ItemType_hpp

#include <fstream>
#include <iostream>
#include "StrTypeAugmented.h"

const int MAX_ITEMS = 25;

enum RelationType {LESS, EQUAL, GREATER};
class HouseType
{
public:
void GetFromFile(std::ifstream&);
void WriteToFile(std::ofstream&);
void GetFromUser();
void PrintHouseToScreen();
void GetNameFromUser();
void PrintNameToScreen();
RelationType ComparedTo(HouseType);

private:
StrType lastName;
StrType firstName;
StrType address;
float price;
int squareFeet;
int bedRooms;
};
#endif
// ItemType.cpp
#include "ItemType.h"

typedef HouseType ItemType;

using namespace std;
// ItemType.cpp is the implementation file for data for the real
// estate manipulation program.

void HouseType::GetFromFile(std::ifstream& file)
{
lastName.GetStringFile(true, NOT_NEW, file);
firstName.GetStringFile(true, NOT_NEW, file);
address.GetStringFile(true, NOT_NEW, file);
file >price >squareFeet >bedRooms;
}

void HouseType::WriteToFile(std::ofstream& file)
{

lastName.PrintToFile( false, file);
firstName.PrintToFile(true, file);
address.PrintToFile(true, file);
file << endl << price << endl;
file << squareFeet << endl;
file << bedRooms << endl;
}

void HouseType::GetFromUser()
{

cout << "Enter last name; press return." << endl;
lastName.GetString(true, NOT_NEW);
cout << "Enter first name; press return." << endl;
firstName.GetString(true, NOT_NEW);
cout << "Enter address; press return." << endl;
address.GetString(true, NOT_NEW);
cout << "Enter price, square feet, number of bedrooms;"
<< " press return." << endl;
cin >price >squareFeet >bedRooms;
}

void HouseType::PrintHouseToScreen()
{

firstName.PrintToScreen( false);
cout << " ";
lastName.PrintToScreen( false);
address.PrintToScreen(true);
cout << endl << "Price: " << price << endl;
cout << "Square Feet: " << squareFeet << endl;
cout << "Bedrooms: " << bedRooms << endl;
}

void HouseType::GetNameFromUser()
{

cout << "Enter last name; press return." << endl;
lastName.GetString(true, NOT_NEW);
cout << "Enter first name; press return." << endl;
firstName.GetString(true, NOT_NEW);
}

void HouseType::PrintNameToScreen()
{

firstName.PrintToScreen( false);
cout << " ";
lastName.PrintToScreen( false);
cout << endl;
}

RelationType HouseType::ComparedTo(HouseType house)
{
if (lastName < house.lastName)
return LESS;
else if (house.lastName < lastName)
return GREATER;
else if (firstName < house.firstName)
return LESS;
else if (house.firstName < firstName)
return GREATER;
else return EQUAL;
}

</code>
ERROR:
multiple definition of
`HouseType::GetFromFile(std::basic_ifstream<char,
std::char_traits<char&)'
first defined here
multiple definition of
`HouseType::WriteToFile(std::basic_ofstream<char,
std::char_traits<char&)'
etc..
Apr 11 '07 #4
ni**********@st.com wrote:
basic rule: member function should be in implementation file or should
be static/inline(if in .h file)
Please don't top post.

The member definitions are in the source file.
zf*****@mail.com wrote:
>>Similar problem to the previous post. I have created a project with
about 7 files including 3 header files and 3 implementation files. I
am getting a multiple definition error when compiling for one specific
file of class. I have checked that if there is more than one
allocation of storage for identifiers, this error arises. But I don't
see where the problem lies. Any suggestions?

<code>
//ItemType.h
#ifndef ItemType_hpp // I was told to include this directives
#define ItemType_hpp

#include <fstream>
#include <iostream>
#include "StrTypeAugmented.h"

const int MAX_ITEMS = 25;

enum RelationType {LESS, EQUAL, GREATER};
class HouseType
{
public:
void GetFromFile(std::ifstream&);
void WriteToFile(std::ofstream&);
void GetFromUser();
void PrintHouseToScreen();
void GetNameFromUser();
void PrintNameToScreen();
RelationType ComparedTo(HouseType);

private:
StrType lastName;
StrType firstName;
StrType address;
float price;
int squareFeet;
int bedRooms;
};
#endif
// ItemType.cpp
#include "ItemType.h"

typedef HouseType ItemType;

using namespace std;
// ItemType.cpp is the implementation file for data for the real
// estate manipulation program.

void HouseType::GetFromFile(std::ifstream& file)
{
lastName.GetStringFile(true, NOT_NEW, file);
firstName.GetStringFile(true, NOT_NEW, file);
address.GetStringFile(true, NOT_NEW, file);
file >price >squareFeet >bedRooms;
}

void HouseType::WriteToFile(std::ofstream& file)
{

lastName.PrintToFile( false, file);
firstName.PrintToFile(true, file);
address.PrintToFile(true, file);
file << endl << price << endl;
file << squareFeet << endl;
file << bedRooms << endl;
}

void HouseType::GetFromUser()
{

cout << "Enter last name; press return." << endl;
lastName.GetString(true, NOT_NEW);
cout << "Enter first name; press return." << endl;
firstName.GetString(true, NOT_NEW);
cout << "Enter address; press return." << endl;
address.GetString(true, NOT_NEW);
cout << "Enter price, square feet, number of bedrooms;"
<< " press return." << endl;
cin >price >squareFeet >bedRooms;
}

void HouseType::PrintHouseToScreen()
{

firstName.PrintToScreen( false);
cout << " ";
lastName.PrintToScreen( false);
address.PrintToScreen(true);
cout << endl << "Price: " << price << endl;
cout << "Square Feet: " << squareFeet << endl;
cout << "Bedrooms: " << bedRooms << endl;
}

void HouseType::GetNameFromUser()
{

cout << "Enter last name; press return." << endl;
lastName.GetString(true, NOT_NEW);
cout << "Enter first name; press return." << endl;
firstName.GetString(true, NOT_NEW);
}

void HouseType::PrintNameToScreen()
{

firstName.PrintToScreen( false);
cout << " ";
lastName.PrintToScreen( false);
cout << endl;
}

RelationType HouseType::ComparedTo(HouseType house)
{
if (lastName < house.lastName)
return LESS;
else if (house.lastName < lastName)
return GREATER;
else if (firstName < house.firstName)
return LESS;
else if (house.firstName < firstName)
return GREATER;
else return EQUAL;
}

</code>
ERROR:
multiple definition of
`HouseType::GetFromFile(std::basic_ifstream<char ,
std::char_traits<char&)'
first defined here
multiple definition of
`HouseType::WriteToFile(std::basic_ofstream<char ,
std::char_traits<char&)'
etc..


--
Ian Collins.
Apr 11 '07 #5
OK sorry imessed...
code seems fine....
problem i guess will be in Makefile asIon said, multiple inclusion of
source file
Ian Collins wrote:
ni**********@st.com wrote:
basic rule: member function should be in implementation file or should
be static/inline(if in .h file)

Please don't top post.

The member definitions are in the source file.
zf*****@mail.com wrote:
>Similar problem to the previous post. I have created a project with
about 7 files including 3 header files and 3 implementation files. I
am getting a multiple definition error when compiling for one specific
file of class. I have checked that if there is more than one
allocation of storage for identifiers, this error arises. But I don't
see where the problem lies. Any suggestions?

<code>
//ItemType.h
#ifndef ItemType_hpp // I was told to include this directives
#define ItemType_hpp

#include <fstream>
#include <iostream>
#include "StrTypeAugmented.h"

const int MAX_ITEMS = 25;

enum RelationType {LESS, EQUAL, GREATER};
class HouseType
{
public:
void GetFromFile(std::ifstream&);
void WriteToFile(std::ofstream&);
void GetFromUser();
void PrintHouseToScreen();
void GetNameFromUser();
void PrintNameToScreen();
RelationType ComparedTo(HouseType);

private:
StrType lastName;
StrType firstName;
StrType address;
float price;
int squareFeet;
int bedRooms;
};
#endif
// ItemType.cpp
#include "ItemType.h"

typedef HouseType ItemType;

using namespace std;
// ItemType.cpp is the implementation file for data for the real
// estate manipulation program.

void HouseType::GetFromFile(std::ifstream& file)
{
lastName.GetStringFile(true, NOT_NEW, file);
firstName.GetStringFile(true, NOT_NEW, file);
address.GetStringFile(true, NOT_NEW, file);
file >price >squareFeet >bedRooms;
}

void HouseType::WriteToFile(std::ofstream& file)
{

lastName.PrintToFile( false, file);
firstName.PrintToFile(true, file);
address.PrintToFile(true, file);
file << endl << price << endl;
file << squareFeet << endl;
file << bedRooms << endl;
}

void HouseType::GetFromUser()
{

cout << "Enter last name; press return." << endl;
lastName.GetString(true, NOT_NEW);
cout << "Enter first name; press return." << endl;
firstName.GetString(true, NOT_NEW);
cout << "Enter address; press return." << endl;
address.GetString(true, NOT_NEW);
cout << "Enter price, square feet, number of bedrooms;"
<< " press return." << endl;
cin >price >squareFeet >bedRooms;
}

void HouseType::PrintHouseToScreen()
{

firstName.PrintToScreen( false);
cout << " ";
lastName.PrintToScreen( false);
address.PrintToScreen(true);
cout << endl << "Price: " << price << endl;
cout << "Square Feet: " << squareFeet << endl;
cout << "Bedrooms: " << bedRooms << endl;
}

void HouseType::GetNameFromUser()
{

cout << "Enter last name; press return." << endl;
lastName.GetString(true, NOT_NEW);
cout << "Enter first name; press return." << endl;
firstName.GetString(true, NOT_NEW);
}

void HouseType::PrintNameToScreen()
{

firstName.PrintToScreen( false);
cout << " ";
lastName.PrintToScreen( false);
cout << endl;
}

RelationType HouseType::ComparedTo(HouseType house)
{
if (lastName < house.lastName)
return LESS;
else if (house.lastName < lastName)
return GREATER;
else if (firstName < house.firstName)
return LESS;
else if (house.firstName < firstName)
return GREATER;
else return EQUAL;
}

</code>
ERROR:
multiple definition of
`HouseType::GetFromFile(std::basic_ifstream<cha r,
std::char_traits<char&)'
first defined here
multiple definition of
`HouseType::WriteToFile(std::basic_ofstream<cha r,
std::char_traits<char&)'
etc..


--
Ian Collins.
Apr 11 '07 #6
ni**********@st.com wrote:
OK sorry imessed...
code seems fine....
problem i guess will be in Makefile asIon said, multiple inclusion of
source file
*Please* don't top-post!

--
Ian Collins.
Apr 11 '07 #7

Ian Collins wrote:
ni**********@st.com wrote:
OK sorry imessed...
code seems fine....
problem i guess will be in Makefile asIon said, multiple inclusion of
source file

*Please* don't top-post!

--
Ian Collins.
ok

Apr 11 '07 #8
ni**********@st.com wrote:
Ian Collins wrote:
>>ni**********@st.com wrote:
>>>OK sorry imessed...
code seems fine....
problem i guess will be in Makefile asIon said, multiple inclusion of
source file

*Please* don't top-post!
Or quote signatures!
ok
--
Ian Collins.
Apr 11 '07 #9
Thanks for the help guys; but I have tried to inline the function and
even commented the one function out and it still returns as a multiple
definition. Now you mentioned another source file, I dont have any
other file in the project where the function is defined. Can someone
help? I can send all my files if necessary.

Apr 11 '07 #10

<zf*****@mail.comwrote in message
news:11**********************@d57g2000hsg.googlegr oups.com...
Thanks for the help guys; but I have tried to inline the function and
even commented the one function out and it still returns as a multiple
definition. Now you mentioned another source file, I dont have any
other file in the project where the function is defined. Can someone
help? I can send all my files if necessary.
(Please quote enough of what you're talking about that we don't have to
search previous posts to know what you're referring to.)

Are you including "ItemType.cpp" somewhere, instead of "ItemType.h"?

If not, then how about seeing the rest of the error messages? It looks like
you left out the info about what file was including what other file when you
copied the error messages here. Also, maybe some other error exists,
causing these errors as a side effect.

-Howard
Apr 11 '07 #11

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

Similar topics

2
by: Jochen Zeischka | last post by:
Hi everybody! I have a question concerning code organisation. Suppose I have the following header file: #ifndef SOME_NAME #define SOME_NAME namespace N { void F()
11
by: Georg Teichtmeister | last post by:
Hello! We are developing a math - library for realtime applications and want to use some given mathlibraries as base(ipp, MTL, .. ). Our library is a wrapper for those and you should be able to...
5
by: Charles L | last post by:
Can someone explain to me what the following means? "C permits multiple definitions of a variable in any given namespace, provided the definitions are the same and it generates only a single...
9
by: lbj137 | last post by:
I have two files: A.c and B.c. In both files I define a global variable, int xxxx; When I compile with a green hills compiler (and also i think with a GNU compiler) I get no errors or warnings....
2
by: jhe | last post by:
I have a user control HeaderControl which was shared by multiple Asp.Net Pages (.aspx), sometimes when I make some changes to our website and restart iis, it will have the CS1595 error, but when I...
11
by: lars.uffmann | last post by:
Easily described problem: Using g++ version 3.3.5 under suse 9.3, bla.h: ----------- #ifndef myTEST #define myTEST ZFSInt test; #endif
3
by: Jens Müller | last post by:
I have a file here with several enums: #ifndef PLANARSEP_OPTIMIZE_H #define PLANARSEP_OPTIMIZE_H enum fund_cycle_behavior_t {PASS_MODE_FIRST, PASS_MODE_BEST, PASS_MODE_ALL};
6
by: Gaijinco | last post by:
I'm having a weird error compiling a multiple file project: I have three files: tortuga.h where I have declared 5 global variables and prototypes for some functions. tortuga.cpp where I...
3
by: Antonio Rivas | last post by:
Hello all. I've got a problem of multiple definition in a program that at first glance looks correct (I won't type the whole code, just the relevant one and as examples since seems is a linkage...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.