是否必须在C++文件中写入头文件中声明的变量的类型
Do you have to write the type of a variable declared in a header file in a C++ file?
我正在尝试做一些游戏编程。为此,我必须将我的类拆分为不同的文件。我的头文件看起来有点像这样:
#ifndef FOO_H
#define FOO_H
#include <someheader>
class Foo {
private:
int someInt;
public:
void setValue(int someValue);
};
那么当我在 cpp 文件中使用 someInt
时,我可以这样做吗?
void Foo::setValue(int someValue) {
someValue = someInt;
}
还是我必须写int someInt
?
提前致谢
它应该是
void Foo::setValue(int someValue) { someInt = someValue ; }
使其成为集合属性
相关文章:
- .cpp和.h文件中的模板专用化声明
- 在 .h 文件中的类中声明静态变量和在.cpp文件中声明"global"变量有什么区别
- 用"=default"声明的函数应该只在头文件中执行
- 调用在 HXX 文件中声明的静态数据成员
- 如何在 c++ 的不同文件中声明类?
- 如何在头文件中声明类模板(由于循环依赖关系)
- 声明要在 qml 和 cpp 文件中使用的全局字符串
- 在.cpp文件之间传递结构声明,而不使用全局头文件
- 为什么要将函数声明和定义放在单独的文件中
- 枚举前向声明与头文件
- 在命名空间中声明变量,在 main 中定义它,使其对所有其他文件可见
- 在带有类型保护的模板文件中使用前向声明
- 在指向现有内存地址的 hpp 文件中声明成员函数的最佳方法
- 在多个头文件中从接口声明被覆盖的函数时,如何避免重复代码?
- 应该在类中的文件声明为静态
- 是否应从头文件声明中排除辅助函数?(C++)
- 哪个C++头文件声明 strlen
- 如何为头文件声明“#include”以避免“error lnk2005”
- 打开文件和关闭文件声明定位:最佳做法,优点,缺点
- 说双向文件声明不隐式设置标志是否正确