c++ - 在类构造函数中调用包含类的构造函数

标签 c++ constructor static

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.
}

两个问题:

  1. 调用的真的是 fileName 类的构造函数吗?
  2. fileName 的构造函数是否被调用时是静态的 像这样?

问候 直

最佳答案

  1. 是的 - 这是 fileName 类的真正构造函数 - 没有返回值,方法的名称与类的名称相同。

    <
  2. 这不是对构造函数的调用,而是构造函数的定义(我猜 :: 是让您感到困惑的地方):

    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/

相关文章:

c# - 静态类库的替代品

c++ - 将非静态方法指针作为参数传递给另一个方法

c++ - 将指针声明为类成员 C++

java - 如何避免制作冗长的构造函数

c++ - 移动构造函数 C++

c++ - lcov 问题 : weird duplicate constructor marked as not covered & function not marked as covered, 即使其行已被执行

java - 如何使用静态变量和线程提高 Java 性能?

c++ - 奇怪的线程堆栈

c++ - xbox 360 Controller 功能的链接器错误

c++ - 使用使用 std::async 创建的线程发送 MPI 的线程安全