使用指令类静态函数? [英] Using-directive class static functions?
问题描述
我使用一个在 TCODConsole
类中具有很多功能的API作为静态函数。现在我认为它是在一个命名空间,所以我写道:使用命名空间TCODConsole;
。然后我发现 TCODConsole
不是一个命名空间,而是一个类。
I am using an API that has a lot of functions in a class named TCODConsole
as static functions. Now I thought that it was in a namespace, so I wrote: using namespace TCODConsole;
. Then I found out that TCODConsole
ain't a namespace, but a class.
有没有办法导入那么这些函数的使用方式与使用使用命名空间
Is there a way to import those functions in a similar way as you would use using namespace
?
推荐答案
虽然我可能误解了这个问题,但如果缩短资格是目标,
;
typedef
>
Though I may misunderstand the question,
if shortening the qualification is the objective,
does typedef
ing like the following meet the purpose?
struct TCODConsole {
static void f();
static void g();
};
int main() {
typedef TCODConsole T;
T::f();
T::g();
}
或者,如果 TCODConsole
可以被实例化,
因为 static
成员函数可以用与
非静态成员函数相同的形式调用,以下代码可能满足目的:
Alternatively, if the class TCODConsole
can be instantiated,
since static
member function can be called with the same form as
non-static member function, the following code might meet the purpose:
int main() {
TCODConsole t;
t.f();
t.g();
}
这篇关于使用指令类静态函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!