Z
zfareed
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:fstream&);
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:fstream& 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:rintHouseToScreen()
{
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:rintNameToScreen()
{
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..
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:fstream&);
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:fstream& 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:rintHouseToScreen()
{
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:rintNameToScreen()
{
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..