如何在 c++ 中扩展 mpz_class

发布于 2025-01-13 02:09:06 字数 397 浏览 4 评论 0原文

我想创建我自己的类,它与 mpz_class 类似,但有一些额外的方法。然而,我听说扩展 std 类不是一个好主意。这个建议是否适用于这里或者我可以安全地这样做:

class MyBigInt : public mpz_class {
public:
    long double specialMethod() {
        //do something that returns a long double
    }
}

我对扩展感兴趣的原因是我仍然希望能够

mpz_class a,b,c;
a=5;
b=6;
c=a+b;

这样做,如果扩展是一个坏主意我需要一些如何弄清楚如何使上述工作与我自己的类一起工作。

I want to create my own class that is similar to mpz_class except has a few extra methods. I have however heard it is not a good idea to extend std classes. Does this advice apply here or can I safely do:

class MyBigInt : public mpz_class {
public:
    long double specialMethod() {
        //do something that returns a long double
    }
}

The reason I am interested in extending is I still want the ability to do

mpz_class a,b,c;
a=5;
b=6;
c=a+b;

so if extending is a bad idea I need to some how figure out how to make the above work with my own class.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文