【发布时间】:2015-05-21 10:02:16
【问题描述】:
为什么要创建一个只有静态和友元方法的类?
例如:
namespace Image
{
GLuint LoadImage(std::string name);
GLuint LoadImage(std::string name, const int min, const int mag, const int wrapx, const int wrapy);
GLuint LoadImage(std::string name, unsigned int& width, unsigned int& height);
unsigned char* LoadImageData(std::string name, unsigned int& width, unsigned int& height);
class ImagePrivate
{
static ILuint DevilLoadImage(std::string name);
friend GLuint LoadImage(std::string name);
friend GLuint LoadImage(std::string name, const int min, const int mag, const int wrapx, const int wrapy);
friend GLuint LoadImage(std::string name, unsigned int& width, unsigned int& height);
friend unsigned char* LoadImageData(std::string name, unsigned int& width, unsigned int& height, unsigned int& bpp);
};
}
友元方法使用 ImagePrivate::DevilLoadImage。
如果你已经有一个命名空间(图片),你为什么要创建一个类?我以为一个类是用来创建对象的,但在这种情况下,并没有创建任何对象。
非常感谢!
【问题讨论】:
-
例如,您不能将命名空间作为模板参数传递...命名空间更像是一个静态概念(编译时),而不是作为虚拟表存在的类。
-
@Jean-BaptisteYunès:只有多态类“有某种存在”作为运行时元数据。这个类不是多态的。
标签: c++ static-methods friend