cplusplus

c++学习

上一篇 / 下一篇  2011-08-13 10:31:41 / 个人分类:C++

写个Gtkmm的测试程序,遇到问题,测试一下测试代码
#include <stdio.h>

class Test1
{
public:
    Test1(int x);
    ~Test1();
};

Test1::Test1(int x)
{
    printf("test1 co\n");
}

Test1::~Test1()
{
    printf("test1 de\n");
}

class Test2
{
public:
    Test2();
    ~Test2();
    Test1 t1(2);//不可以
//    Test1 *t1;
};

Test2::Test2()
{
    printf("test2 co\n");
}

Test2::~Test2()
{
    printf("test2 de\n");
}

int main(int argc, char* argv[])
{
    Test2 t2;
    return 0;
}
对C++还不是很熟练呢。继续学习
对象在类中是不允许初始化的。有参数的类对象在另一个类中的声明只能用指针变量?
o(∩∩)o...哈哈,改一改
class Test2
{
public:
    Test2();
    ~Test2();
    Test1 t1;
//    Test1 *t1;
};

Test2::Test2() : t1(2)
{
    printf("test2 co\n");
}


TAG:

 

评分:0

我来说两句

Open Toolbar