C ++:如何设计实用程序类? [英] C++: How to design a utility class?

查看:161
本文介绍了C ++:如何设计实用程序类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

但是我不知道我应该去静态方法,只是一个标题,一个类,或者别的什么?

But I don't know if I should go for static methods, just a header, a class, or something else?

什么是最佳实践?但是,我不想有一个实用程序类的实例。

What would be best practice? But, I don't want to have an instance of a utility class.

我想添加如下函数:

Uint32 MapRGB (int r, int g, int b);
const char* CopyString(const char* char);
// etc. You know: utility methods...


推荐答案

不要把它们放在类中;

Don't put them in a class; just make them non-member functions at namespace scope.

没有规则说每个函数都必须是某个类的成员函数。

There's no rule that says every function has to be a member function of some class.

这篇关于C ++:如何设计实用程序类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆