c++ - 拥有一个不需要创建对象的类是不好的做法吗?
问题描述
我需要制作一个具有两种解析方法的美化文本解析器,具体取决于配置文件这就是我想出的。
class Compiler
{
public:
static void compile(const std::string& filepath);
private:
Compiler() {}
static void SimpleCompilation(std::ifstream& fin, std::ofstream& fout);
static void AdvancedCompilation(std::ifstream& fin, std::ofstream& fout);
static unsigned int numOfChars(const std::string& target, const std::string& charset);
};
从某种意义上说,我希望这个类是一个带有一些子函数的函数。我希望用户能够访问编译,编译选择它使用的两种解析器类型中的哪一种,而不创建类的对象。
这是不好的做法吗?我应该创建一个编译命名空间并将所有这些子函数放入一个巨大的编译函数中,还是有办法阻止用户从命名空间调用选择函数?
解决方案
推荐阅读
- c++ - 在 Windows 上管道到 ffmpeg
- python - Pygame 与 cx_Freeze 一起使用,但当我运行可执行文件时,窗口中没有显示任何内容
- python - 有没有办法将 mxn 矩阵(1)与 pxn 矩阵(2)批量相乘,其中矩阵(2)的每一行都是标量?
- python - 为什么此替换方法无法正常工作
- python - 从 100 开始数到 999
- r - R:计算基函数的惩罚矩阵?
- swift - iOS 11 SDK:AVPlayerViewController 不等同于 willEndFullScreenPresentationWithAnimationCoordinator 被调用
- regex - 使用列表跳过字典中的数字/单词组合
- php - 如何保存 PHP 变量 $SAddress1 = "1234 My Address" 以便稍后在表单字段中的网站上使用 3 页?Apache、PHP、MySql 网站
- c# - 我的传送脚本导致我的玩家随机传送回集线器