代码行 1 中的"(void)"有什么用?
what's the use of '(void)' in code line 1?
我正在练习C++中的反射,代码如下:
typedef void* (*PTRCreateObject)(void);
class ClassFactory{
private:
map<string, PTRCreateObject>m_classMap;
ClassFactory(){};
public:
void* getClassByName(string className);
void registClass(string name, PTRCreateObject method);
static ClassFactory& getInstance();
};
这是 C 的遗留物。
在 C 语言中
void* (*)(void)
是指向不带参数的函数的指针。
void* (*)()
是指向采用未指定参数的函数的指针。
在C++
两者都意味着没有参数。
()
是惯用语,(void)
允许向后兼容。
这只是表示无参数的另一种方式。
typedef void* (*PTRCreateObject)(void);
和
typedef void* (*PTRCreateObject)();
两者都是等价的。
返回签名void*
只是返回指向某个未知类型的指针。
相关文章:
- 我应该使用什么来代替void作为变体中的替代类型之一
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- 0-1背包代码中的错误.我的代码中有什么错误
- 在 .h 文件中的类中声明静态变量和在.cpp文件中声明"global"变量有什么区别
- 有什么好的方法可以让系统调用代理允许在单元测试中进行模拟
- 是什么导致了Unity 3D中的"错误线程异常"?
- 初始化或分配空字符串文字到指向 C 中的 char 的指针或指向 C++ 中 const char 的指针的原因是什么
- 标准 N3337 5.2.10 第 7 条中的C++"类型"是什么意思?
- c++20[[no.unique_address]]中的新功能是什么
- 当我们为(;;) 写作时,它做了什么?for 循环中的双分号有什么作用?
- 在 c++ 中对类中的 c 字符串动态数组进行排序的最佳方法是什么?
- 此代码中的操作流程是什么?C/C++.
- 我的逻辑反转字符串中的元音有什么问题?
- 跟踪日志中的T.11803()是什么意思?
- C 中的常量限定符和 C++ 中的常量限定符有什么区别?
- 通过比较C++中的行在 txt 文件中搜索的最简单方法是什么?
- 以下代码中的函数模板有什么问题?
- C++中的标点符号是什么
- 将信息输入到下面显示的结构向量中的正确语法/格式是什么
- 减法中的"0"是什么意思?