一个类应该有静态成员还是非静态成员

编程入门 行业动态 更新时间:2024-10-25 20:27:03
本文介绍了一个类应该有静态成员还是非静态成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图找出什么时候让一个类同时具有静态和非静态功能是合适的.又名:

I'm trying to figure out when it would be appropriate for a class to have both static and non-static functions. AKA:

$obj = new ClassA; $obj->doOOPStuff(); $something = ClassA::doStaticStuff();

注意:此示例在PHP中完成,但是问题与语言无关.

似乎,如果您有一个要实例化的类,则可以静态调用的任何函数很可能属于另一个类.

It seems that if you have a class that is meant to be instantiated, any functions that can be called statically, most likely belong in another class.

在任何可行的情况下,我会有一个使用静态和非静态成员的类吗?

Is there any viable cases where I would have a class that used static AND non-static members?

推荐答案

一个示例:何时必须以特定方式进行创建.

One example: when Creation has to happen in a specific way.

class Foo { public: static Foo* Create(...params...); private: Foo(); };

更多推荐

一个类应该有静态成员还是非静态成员

本文发布于:2023-11-16 06:27:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1601816.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静态   成员   是非

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!