// this is the first point class header
class Point : public CWaypoint{
public: //temporarily
string m_description;
public:
Point();
virtual ~Point();
void print();
Point(string name, string description, double latitude, double longitude);
void getAllDataByReference( string& name,string& description, double& latitude,double& longitude);
};
// This is the database class header
class Database
{
private:
Point m_POI[10]; // Point is the other class
int m_noPoi;
public:
Database();
virtual ~Database();
void addPoI(string name,string description,double latitude,double longitude);
Point * getPointerToPoi(string name);
}
答案 0 :(得分:0)
首先,要添加到数组中,您可以依赖隐式声明的复制赋值运算符,该运算符执行所有字段的浅表副本:
void Database::addPoI(string name,string description,double latitude,double longitude) {
if (m_noPoi >= 10) // handle error
m_POI[m_noPoi++] = Point(name, description, latitude, longitude);
}
由于数据是私有的,因此您无法直接访问它(忽略“朋友”发货)。但是,您可以通过point::getAllDataByReference()
读取数据(通过副本)。