是否必须在C++文件中写入头文件中声明的变量的类型

Do you have to write the type of a variable declared in a header file in a C++ file?

本文关键字:文件 声明 变量 类型 C++ 是否      更新时间:2023-10-16

我正在尝试做一些游戏编程。为此,我必须将我的类拆分为不同的文件。我的头文件看起来有点像这样:

#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 ; }

使其成为集合属性