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

找c++错的

烟雾中的迷茫 发布于 2011-10-24 18:32, 693 次点击
程序代码:
#include<iostream>
using namespace std;

class Test
{
    int x,y;
public:
    Test();
    void show()
    {
        cout<<x<<","<<y<<"|"<<endl;
    }
    ~Test();
};

Test::Test()
{
    x=3;
    y=4;
}

int main(int argc,char *argv[])
{
    Test Ta;
    Ta.show();
    return 0;
}
想不通 求指教
6 回复
#2
nomify2011-10-24 18:41
析构函数没有实现。
#3
烟雾中的迷茫2011-10-24 21:05
这个它一定要实现吗? 那可以怎么改
#4
a3733392052011-10-24 21:23
回复 楼主 烟雾中的迷茫
程序代码:
#include<iostream>
using namespace std;

class Test
{
    int x,y;
public:
    Test();
    void show()
    {
        cout<<x<<","<<y<<"|"<<endl;
    }
    ~Test(){};
};

Test::Test()
{
    x=3;
    y=4;
}

int main(int argc,char *argv[])
{
    Test Ta;
    Ta.show();
    return 0;
}

#5
烟雾中的迷茫2011-10-25 07:06
好吧 谢了
#6
Alphalab2011-10-25 14:07
类里面应该封装数据成员,int x, int y 应该声明为private.
#7
乔哥2011-10-25 16:59
运行结果是3,4
1