注册 登录
编程论坛 C++教室

输出有问题VC6.0

waja 发布于 2014-03-14 22:00, 515 次点击
#include <iostream.h>
struct sample
{
private:
    int length, width, s;
public:
    sample(int i, int j)//构造函数
    {
        length = i;
        width = j;
        s = length * width;
        cout << s <<'\t' << "构造函数被调用"<< endl;
    }
    ~sample()
    {
        cout << length <<'\t'<< width << '\t' ;
        cout << s <<'\t' << "构造函数被调用"<< endl;//这句话输出有问题呀?
        //cout << s << '\t'<< "析构函数被调用"<<endl;

    }
    sample(const sample &);

};

sample :: sample( const sample &obj1)

{
    length = obj1.length;
    width =  obj1.width;
    cout <<"赋值构造函数被调用"<<endl;
}
void main()
{
    sample obj1(15, 6);
    sample obj2(obj1);
    sample obj3 = obj1;
}




7 回复
#2
rjsp2014-03-14 22:59
有什么问题呀?
你的文字表达能力要加强呀
#3
三色贝壳2014-03-15 11:21
不知道你说的什么问题,但是sample(const sample &);和sample :: sample( const sample &obj1)好像不是很规范


#4
liusonglin2014-03-15 13:27
这程序很乱,有很多错误
#5
waja2014-03-15 19:11
回复 4楼 liusonglin
确定吗
#6
waja2014-03-15 19:12
回复 3楼 三色贝壳
我要不喜欢这种风格 这是一个例程
#7
waja2014-03-15 19:14
回复 2楼 rjsp
恩恩 的确没有说清楚 主要是希望能够运行下就知道了,没有error ,运行结果会出现 随机值
#8
rjsp2014-03-17 08:37
回复 7楼 waja
因为拷贝构造函数中没有给S赋值
1