我很難解決重新定義錯誤。基本上,我在我的類頭文件中有一個名爲houseClassType的類對象,我也必須在我的結構頭文件中使用houseClassType作爲我的結構中的數組的數據類型。下面是兩個頭文件:如何在不重新定義類對象中的類類型的情況下將數據類型定義爲結構中的int?
房子的頭文件:
#include "Standards.h"
#ifndef house_h
#define house_h
//Definition of class, house
class houseClassType
{
//Data declaration section
private:
int capacityOfGarage;
int yearBuilt;
int listingNumber;
double price;
double taxes;
double roomCounts[3];
string location;
string style;
//Private method to set the county name
string SetCountyName(string);
string SetSchoolDistrictName(string);
//Private method to set school district name
void SetSchoolDistrictName(void);
//Set function for the object
void ExtractLocationData(string& state, string& county, string& city,
string& schoolDistrictName, string& address);
//Methods declaration
public:
///Default Constructor
houseClassType(void);
///Get methods for data members - INLINE
int GetCapacity(void) { return capacityOfGarage; };
int GetYearBuilt(void) { return yearBuilt; };
int GetListingNumber(void) { return listingNumber; };
double GetPrice(void) { return price; };
double GetTaxes(void) { return taxes; };
string GetLocation(void) { return location; };
string GetStyle(void) { return style; };
void GetRoomCounts(double[]);
//Set methods for data members
void SetCapacityOfGarage(int);
void SetYearBuilt(int);
void SetListingNumber(int);
void SetPrice(double);
void SetTaxes(double);
void SetLocation(string);
void SetStyle(string);
void SetRoomCounts(double[]);
//Output methods for data members
void OutputLocationData(ofstream&);
void OutputStyle(ofstream&);
void OutputRoomCounts(ofstream&);
void OutputCapacityOfGarage(ofstream&);
void OutputYearBuilt(ofstream&);
void OutputPrice(ofstream&);
void OutputTaxes(ofstream&);
void OutputListingNumber(ofstream&);
void OutputHouse(ofstream&);
///Destructor
~houseClassType(void);
};
#endif
房地產經紀人的頭文件:
#include "Standards.h"
#ifndef Realtor_h
#define Realtor_h
const int NUMBER_OF_HOMES = 30;
typedef int houseClassType;
struct realtorStructType
{
string agentName;
houseClassType homes[NUMBER_OF_HOMES]; ///Redefinition error here
int numberOfHomes;
};
void InputHomes(ifstream& fin, string agentName, int& numberOfHomes);
#endif
任何幫助將非常感激。
您應該將代碼縮減到[mcve](http://stackoverflow.com/help/mcve)從所有這些代碼行中,只有3-4個與您的問題相關。 – bolov
爲什麼你需要爲typedef使用同名的'houseClassType'?無論如何,如果你想使用相同名稱的不同類型,你需要使用命名空間。 – Barmar
@Barmar你是對的,它不一定是一個typedef。但是,你能否給我一個你稱之爲「使用命名空間」來解決這個問題的例子? – Smiter