gpt4 book ai didi

c++ - Object.memberFunction(argument).MemberFunction(); - 我就是不明白

转载 作者:行者123 更新时间:2023-11-30 01:53:39 25 4
gpt4 key购买 nike

我正在进行一项更大的任务 - 一个虚构的网上银行数据库。一切都很好,只是它需要能够响应这样的调用:

bank.Account("123456").Balance();

bank 是 Bank 类的一个实例,它包含一个 Account 类对象的数组(是的,我被禁止使用大多数 STL)。

想法:我需要 Bank 类中的一个函数 Account & Account ( const char * ),它是 Account 类的友元函数,然后可以调用在 Account 类中声明的 Balance 函数。我这样做对吗?我并不是真的要你为我写代码,我只是想知道我是否朝着正确的方向前进。谢谢。

最佳答案

I need a function Account & Account ( const char * ) in the class Bank that would be a friend function for the class Account and then it is possible to call the Balance function that is declared in the Account class. Am I doing this right?

您不需要任何 friend 类或函数,只需将 getters public 设为:

class Bank {
public:
Account & Account ( const char * );
};

class Account {
public:
Balance& Balance();
};

关于c++ - Object.memberFunction(argument).MemberFunction(); - 我就是不明白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22941264/

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