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

标签 c++

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

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/

相关文章:

c++ - 继承和属性打包

c++ - 将二进制字节 (char*) 转换为 uint64_t*,安全吗?

C++ XML注释生成MSDN风格的CHM

c++ - 如何创建一个从指定内存地址开始的数据结构(不使用 new)?

c++ - 没有定义的函数声明

c++ - 使用openGL的glBindFramebuffer好像没有效果

c++ - 在 android 内核开发 linux 中使用蓝牙

c++ - IOS 上的 OpenCV 来自 C++ 的 haar 级联 xml 文件路径问题

c++ - 覆盖 QAbstractItemModel::index 并访问 std::map

C++ - 查找两个范围的交集