【问题标题】:Friend function for class in dlldll中类的友元函数
【发布时间】:2021-10-14 16:34:07
【问题描述】:

假设我的 dll 中有以下类

class Test { private: int x; };

以及使用我的 dll 的客户端应用程序中的以下功能

void test();

有没有办法让测试类的测试函数成为朋友?

【问题讨论】:

    标签: c++ dll friend


    【解决方案1】:

    有没有办法让测试类的测试函数成为朋友?

    是的,在类定义中添加friend 声明:

    class Test {
    private:
        int x;
        friend void test();
    };
    

    【讨论】:

    • 让我澄清一下。这是否意味着如果我通过添加“friend void test();”使测试类的测试函数成为朋友?那么在课堂上,任何使用我的 dll 的人都可以实现一个名为 test 的函数,从而访问 x 变量?
    • @ArthurTsaturyan 是的,没错。
    • 这太棒了。 Т谢谢!
    • @ArthurTsaturyan 不客气!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-15
    • 1970-01-01
    • 2015-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多