首页 > 解决方案 > 拥有一个不需要创建对象的类是不好的做法吗?

问题描述

我需要制作一个具有两种解析方法的美化文本解析器,具体取决于配置文件这就是我想出的。

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++

解决方案


推荐阅读