我有一个非静态函数的类。由于我的程序的体系结构,我认为使用静态函数会更好,因为该类只是一个实用程序。在某些情况下,我只需要该类的一个功能,因此我认为创建对象是不必要的。基本上我有这个:
class StaticCall
{
public:
StaticCall(){}
static int call_1()
{
std::cout << "In call 1" << std::endl;
call_2();
return 0;
}
static int call_2();
{
std::cout << "In call 2" << std::endl;
return 0;
}
};
int main( int argv, char** argc )
{
std::cout << "Calling 1" << std::endl;
StaticCall::call_1();
std::cout << std::endl;
std::cout << "Calling 2" << std::endl;
StaticCall::call_2();
return 0;
}
它工作正常,但我想知道这种方法是否有任何问题。我可以通过使用其他帖子已经说过的命名空间来实现相同的目的。但是因为我已经有了这个类,所以我想用静态函数来做。