标题:c++默认构造函数
取消只看楼主
hahaflying
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-2-20
 问题点数:0 回复次数:1 
c++默认构造函数

#include <iostream>

using namespace std;

class myClass
{
private:
int a;
public:
myClass(int b = 0):a(b) {}
myClass():a(0) {}
int GetA() const
{
cout << this->a << endl;
}
};


int main()
{
myClass myObject(7);
myObject.GetA();
myClass myObject1(); //为什么不给myObject1()传递参数不行??
myObject1.GetA();
return 0;
}

搜索更多相关主题的帖子: 函数 构造 
2006-02-20 20:16
hahaflying
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-2-20
得分:0 
myClass myObject1();这个语句不能调用构造函数myClass():a(0) {} 吗??
谢谢!
2006-02-20 22:32



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-46370-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.376343 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved