类argList
中的构造函数是指令
args_[0] = fileName(argv[0]);
在搜索方法 fileName(...)
时发现它应该是类 fileName
的构造函数:
inline Foam::fileName::fileName(const char* str) //Construct as copy of character array.
: string(str) //Construct as copy of character array.
{
stripInvalid(); //Strip invalid characters from the given string.
}
两个问题:
- 调用的真的是
fileName
类的构造函数吗? fileName
的构造函数是否被调用时是静态的 像这样?
问候 直
最佳答案
是的 - 这是
<fileName
类的真正构造函数 - 没有返回值,方法的名称与类的名称相同。这不是对构造函数的调用,而是构造函数的定义(我猜
::
是让您感到困惑的地方):inline Foam::fileName::fileName(const char* str) //Construct as copy of character array.
这是对构造函数的调用:
args_[0] = fileName(argv[0]);
C++ 中没有静态构造函数。
关于c++ - 在类构造函数中调用包含类的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20241887/