我有 2 个类, CLASS locationdata 是 CLASS PointTwoD 的私有成员。
班级位置数据
class locationdata
{
public:
locationdata(); //default constructor
locationdata(string,int,int,float,float); //constructor
//setter
void set_sunType(string);
void set_noOfEarthLikePlanets(int);
void set_noOfEarthLikeMoons(int);
void set_aveParticulateDensity(float);
void set_avePlasmaDensity(float);
//getter
string get_sunType();
int get_noOfEarthLikePlanets();
int get_noOfEarthLikeMoons();
float get_aveParticulateDensity();
float get_avePlasmaDensity();
static float computeCivIndex(string,int,int,float,float);
friend class PointTwoD;
private:
string sunType;
int noOfEarthLikePlanets;
int noOfEarthLikeMoons;
float aveParticulateDensity;
float avePlasmaDensity;
};
类点二
class PointTwoD
{
public:
PointTwoD();
PointTwoD(int, int ,locationdata);
void set_x(int);
int get_x();
void set_y(int);
int get_y();
void set_civIndex(float);
float get_civIndex();
locationdata get_locationdata();
bool operator<(const PointTwoD& other) const
{
return civIndex < other.civIndex;
}
friend class MissionPlan;
private:
int x;
int y;
float civIndex;
locationdata l;
};
在我的主要方法中,我试图访问 locationdata 的私有成员但是我收到一个错误:'->' 的基本操作数具有非指针类型'locationdata'
这就是我访问私人成员的方式
int main()
{
list<PointTwoD>::iterator p1 = test.begin();
p1 = test.begin();
locationdata l = p1 ->get_locationdata();
string sunType = l->get_sunType(); // this line generates an error
}