0

C ++の「ヘッドファイル」について質問があります。現在、スーパークラス「ノード」と3つのサブクラス「ファイル、ディレクトリ、ファイル」があります

class Node {
public:
    //declare common interface here
    void setName(string& name);
    const string getName();
    //  const Protection& getProtection();

    //  void setProtection(const Protection&);
    void setCDate(char* cDate);
    char* getCDate();
    long size();

    void streamIn(istream&);
    void streamOut(ostream&);

    Node* getChild(int index);
    virtual void adopt(Node* child);
    virtual void orphan(Node* child);

    virtual void accept(Visitor&) = 0;
    static void destroy(Node*);
protected:
    Node();
    Node(const Node&);
    virtual ~Node();
    virtual bool isWritable() = 0;
private:
    string name;
    char* cDate;
};
class Directory : public Node {
public:
    Directory();
    Directory(string path);
    //redeclare common interface here
    void setName(string& name);
    string getName();
    void setCDate(char* cDate);
    char* getCDate();
    long size();
    Node* getChild(int index);
    virtual void adopt(Node* child);  //add children
    virtual void orphan(Node* child); //let the subnode be free
    virtual void accept(Visitor&);
private:
    list<Node*> _nodes;     //hold its subnode
    string& name;
    char* cDate;
};

ファイルとリンクはクラス ディレクトリと同じです。クラス ビジターは次のとおりです。

class Visitor{
public:
    virtual ~Visitor() {}
    virtual void visitNode(Node*) = 0;
    virtual void visitFile(File*) = 0;
    virtual void visitDirectory(Directory*) = 0;
    virtual void visitLink(Link*) = 0;
protected:
    Visitor();
    Visitor(const Visitor&);
};

それらはそれぞれ異なる head ファイルにあります。これらの head ファイルをインポートする方法を知りたいです

4

3 に答える 3

0

通常、1.h と 2.h などの 2 つのヘッダー ファイルがあり、両方が同じフォルダーにある場合

「ヘッダファイル 1.h」

class A {..}

「ヘッダファイル 2.h」

class B {..}

2.h でクラス A を使用する場合は、2.h に次の行を追加します。

#include "./1.h"   // Change the path if the header is some other directory

2.h ファイルは次のようになります。

#include "./1.h"
class B {..}
于 2013-09-13T10:44:06.170 に答える
0

ファイルの名前が directory.h、file.h、link.h、visitor.h の場合、file.h および link.h ファイルの先頭に directory.h を含める必要があります。

#include "directory.h"

これらのファイルのように、directory.h で定義されたクラス Node が使用されます。同様に、visitor.h には、Visitor 定義で使用されるクラスが定義されているすべてのファイルを含める必要があります。

#include "directory.h"  
#include "file.h"  
#include "link.h" 
于 2013-09-13T10:46:59.290 に答える