c++ - 如何在cpp中访问 parent 的运营商

标签 c++

我创建了一个类,其父级有一个运算符,我一直在尝试访问该父级的运算符。 我无法在网上找到关于我应该如何去做的答案。 有没有人知道? 提前致谢。 代码: out stream 中的运算符按以下方式声明:

( OutStream& operator<<(const char *str);)

类 outStreamencrypted 是 outstream 的子元素:

(class OutStreamEncrypted : OutStream)

outstreamencrypted 中的新运算符按以下方式声明,我想做的是在这个新运算符中使用 outstream 中的运算符。

 OutStreamEncrypted& OutStreamEncrypted::operator<<(const char* str)
        {
            int i = 0;
            char* newStr = NULL;
            while ((str + i) != NULL)
            {
                if (*(str + i) >= 32 && *(str + i) <= 126)
                {
                    *(newStr + i) = *(str + i) + _ceasarValue;
                }
                else
                {
                    *(newStr + i) = *(str + i);
                }
                i++;
            }
            *(newStr + i) = NULL;

我正在尝试调用将字符串打印到文件中的父级 OutStream 运算符。

最佳答案

将运算符作为函数调用应该没问题

OutStreamEncrypted& OutStreamEncrypted::operator<<(const char* str)
{
  ...
  OutStream::operator<<( some_value_to_inject );
  ...
}

关于c++ - 如何在cpp中访问 parent 的运营商,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59115797/

相关文章:

c++ - 访问被参数隐藏的数据成员

c++ - 使用 distcc 在 Ubuntu 上的 i686 系统上交叉编译 x86_64

c++ - C++ 链接器错误 LNK2019

java - jni 无法从 native 库中找到方法?

c++ - 如何使用wt实现ajax请求处理?

c++ - 从 Maya 场景中的现有对象名称构造 MObject

c++ - 我 =++i+++i;在 C++ 中

c++ - 静态无效函数链接错误

c++ - 我收到错误 c++ assertion failure heap corruption detected

c++ - 我如何将一个 int 添加到一个字符串