473,320 Members | 1,953 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,320 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 2773
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.