2016-11-03 19 views
-2
// 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); 
} 
+3

今後、コードにテキストを添付してください。 –

+0

あなたが遭遇した具体的な問題は何ですか? –

+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()まで読むことができます。

関連する問題