嵌套结构声明以及如何访问它们

时间:2015-12-12 08:44:22

标签: c++ data-structures

我无法使用指向嵌套结构的指针,并在我的类的成员函数中的那些结构中使用这些变量。

我声明了这些变量。如果它们在结构的嵌套方面被宣布为正确的,请告诉我。

 const int MAX_ACCOUNT_COUNTRY = 36;
    const int MAX_ACCOUNT_CITY = 50;
    const int MAX_ACCOUNT_NAME = 10;
    const int MAX_NUMBER = 16;
    const int MAX_ACCOUNT_ADDRESS = 25;
    const int MAX_ACCOUNT_EMAIL = 50;
    const int MAX_OFFICE_HOURS = 20;
    const int businessID = 0;
    const int residentalID = 1;

    typedef char accountCountry[MAX_ACCOUNT_COUNTRY + 1];
    typedef char accountCity[MAX_ACCOUNT_CITY + 1];
    typedef char accountName[MAX_ACCOUNT_NAME + 1];
    typedef char phoneNumberFormat[MAX_NUMBER + 1];
    typedef char accountAddress[MAX_ACCOUNT_ADDRESS + 1];
    typedef char accountEmail[MAX_ACCOUNT_EMAIL + 1];
    typedef char officeHours[MAX_OFFICE_HOURS + 1];

    typedef phoneBook * phonebookPtr;

public:
    Phonebook(const int numPages);
    ~Phonebook();
    void addAccount(const int);
    void removeAccount(const int);
    void editAccount(const int);
    void viewPhonebook();

private:
    struct phoneBook{
        struct businessAccountEntry
        {
            const int businessID;
            accountCountry businessCountry;
            accountCity businessCity;
            accountName businessName;
            accountName accountHolder;
            accountAddress businessAddress;
            accountAddress mailingAddress;
            phoneNumberFormat phoneNumber;
            phoneNumberFormat faxNumber;
            accountEmail businessEmail;
            officeHours businessOfficeHours;
        };

        struct residentialAccountEntry
        {
            const int residentialID;
            accountName residentName;
            accountAddress mailingAddress;
            phoneNumberFormat phoneNumber;
        };
    };

    phonebookPtr thePhonebook;

    int counterID = 0;

    Phonebook();
    Phonebook(Phonebook &);
};

如何在我的班级中为我的成员函数访问结构businessAccountEntry内的变量?

1 个答案:

答案 0 :(得分:0)

给他们一个像

这样的名字
struct phoneBook{
    struct businessAccountEntry
    {
        const int businessID;
        accountCountry businessCountry;
        accountCity businessCity;
        accountName businessName;
        accountName accountHolder;
        accountAddress businessAddress;
        accountAddress mailingAddress;
        phoneNumberFormat phoneNumber;
        phoneNumberFormat faxNumber;
        accountEmail businessEmail;
        officeHours businessOfficeHours;
    } businessAccount;

    struct residentialAccountEntry
    {
        const int residentialID;
        accountName residentName;
        accountAddress mailingAddress;
        phoneNumberFormat phoneNumber;
    } residentialAccount;
};

并使用它:thePhonebook->residentialAccount.residentialID