C++中的整数和函数

lil*_*lzz 0 c++

class Foo
{
public:
  // single parameter constructor, can be used as an implicit conversion
  Foo (int foo) : m_foo (foo) 
  {
  }

  int GetFoo () { return m_foo; }

private:
  int m_foo;
};
Run Code Online (Sandbox Code Playgroud)

m_foo是私有部分中定义的整数,但是m_foo(foo)是什么?看起来像一个功能.

m_foo既是整数又是函数?这是如何运作的?

而Foo(int foo)构造函数正在扩展m_foo函数.

Dav*_*nan 5

Foo (int foo) : m_foo (foo) 
Run Code Online (Sandbox Code Playgroud)

这是一个初始化列表.它初始化m_foo为有价值foo.