C++构造函数是否可以重载为普通函数?

构造函数重载为普通函数
1 #include <iostream>
2
3  class ConstructorTest
4 {
5  public:
6 ConstructorTest(int i):mI(i) {std::cout << "ConstructorTest Constructor." << std::endl;}
7 int ConstructorTest() {std::cout << "ConstructorTest Function." << std::endl; return 0;}
8  private:
9 int mI;
10 };

上面的代码编译出错!

结论:C++构造函数不能重载为普通函数

相关文章:

  • 2022-12-23
  • 2021-08-10
  • 2021-08-18
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2021-08-21
  • 2021-11-06
猜你喜欢
  • 2022-12-23
  • 2022-02-08
  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
相关资源
相似解决方案