我在AirportDBAccessor.h中声明了一个这样的类:
class AirportDBAccessor
{
private:
EDS::uint8_t *pAptData;
EDS::sint32_t namesStartLoc;
EDS::bool_t AirportTextDbInitialized;
// Airport Data
// apt_dir.dat file ptr
const EDS::char8_t *AptIdxRecFilePtr;
const EDS::char8_t *AptDataFilePtr;
// apt_dat.dat file ptr
const EDS::char8_t *AptDatFilePtr;
EDS::uint32_t TempDirNumRec;
EDS::uint32_t AirportDatFileSize;
EDS::sint32_t AirportTextDbNumRecords;
EDS::uint32_t MaxValidAirportDatIndex;
EDS::sint32_t AptDirLoc;
EDS::sint32_t AptDataLoc;
EDS::uint32_t GetAirportIndexRec(EDS::sint32_t index);
EDS::sint32_t AptIndexBinarySearch(const EDS::char8_t *icao,
stAirportIndexRecord *AptIdxRec);
public:
AirportDBAccessor();
~AirportDBAccessor();
void InitializeAirportTextDB(EDS::sint32_t dBError);
EDS::uint8_t GetCityStateName (const EDS::char8_t *icao, EDS::char8_t
*CityName, EDS::char8_t *StateName);
void GetRunwayRecord (const EDS::char8_t *icao, const EDS::char8_t
*RunwayName,
EDS::sint32_t *WhichEnd, stRunwayIndexRecord *TempRwyRec);
void GetRwyNotes(EDS::char8_t* RwyNotes, EDS::uint16_t
RunwayNoteStringLength,
EDS::uint32_t RunwayNoteIndex , EDS::uint16_t MAX_LEN);
void GetAirportRecord (const EDS::char8_t *icao, stAirportIndexRecord
*TempRec);
void GetAirportFullName(EDS::char8_t* AirportName, EDS::uint32_t
AirportNameIndex, EDS::uint8_t AirportNameLength);
void GetDataByIndex(EDS::uint32_t FileIndex, EDS::uint8_t DataLength,
EDS::char8_t* DataPtr);
void GetAirportHotelsRecord (EDS::uint32_t FileIndex, EDS::uint32_t
WhichHotel,
stAptHotelsRecord *TempRec);
void GetAirportGndTransRecord (EDS::uint32_t FileIndex, EDS::uint32_t
WhichGndTrans, stAptGndTransRecord *TempRec);
};
现在,我想访问私有成员函数GetAirportIndexRec()。为此,我定义了user_defined.h,如下所示:
#define protected friend class Test_Friend; protected
#define private friend class Test_Friend; private
#include "AirportDbAccessor.h"
#undef protected
#undef private
class Test_Friend
{
public:
//Constructor
Test_Friend::Test_Friend()
{
}
//Accessing private Member function using friend class concept
unsigned long get_GetAirportIndexRec(AirportDBAccessor&
AirportDBAccessor_1)
{
unsigned long index = 0;
unsigned long GetAirportIndexRec_index = 0;
GetAirportIndexRec_index = AirportDBAccessor_1.GetAirportIndexRec(index);
return GetAirportIndexRec_index;
}
};
在main()中,我像下面这样调用:
Void main()
{
EDS::uint32_t Output_index;
AirportDBAccessor AirportDBAccessor_1;
Test_Friend Test_Friend_1;
Output_index = Test_Friend_1.get_GetAirportIndexRec(AirportDBAccessor_1);
}
但是我在user_defined.h中遇到“ GetAirportIndexRec”错误:无法访问在“ AirportDBAccessor”类中声明的私有成员。
有人可以帮我吗?