gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 13:23:12 25 4
gpt4 key购买 nike

我在使用指向嵌套结构的指针以及在我类的成员函数中使用这些结构中的那些变量时遇到问题。

我声明了这些变量。让我知道它们在结构嵌套方面的声明是否正确。

 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 内的变量?

最佳答案

给他们起个像这样的名字

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

关于c++ - 嵌套结构声明以及如何访问它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34237964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com