使用太多静态坏或好? [英] using too much static bad or good?
问题描述
我喜欢使用c ++中的静态函数作为对它们进行分类的方式,如c#does。
i like to use static functions in c++ as a way to categorize them, like c# does.
Console::WriteLine("hello")
但它是好还是坏?
如果函数经常使用我猜它没有关系,但如果不是,他们压力内存?
but is it good or bad ? if the functions are often used i guess it doesn't matter, but if not do they put pressure on memory ?
同样适用于静态const。
The same goes for static const...
推荐答案
但它是好还是坏
but is it good or bad
第一个形容词是不必要的。
The first adjective that comes to mind is "unnecessary". C++ has free functions and namespaces, so why would you need to make them static functions in a class?
在C#和Java 中的静态方法在不可重载的类中使用静态方法>是一种解决方法,因为这些语言没有自由函数(即,直接驻留在命名空间中的函数,而不是类的一部分)。 C ++没有这个缺陷。只需使用命名空间。
The use of static methods in uninstantiable classes in C# and Java is a workaround because those languages don't have free functions (that is, functions that reside directly in the namespace, rather than as part of a class). C++ doesn't have that flaw. Just use a namespace.
这篇关于使用太多静态坏或好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!