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++构造函数不能重载为普通函数

posted on 2010-03-21 20:31  cppfans  阅读(552)  评论(0编辑  收藏  举报