首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

C++静态成员函数的生命周期解决方案

2013-10-23 
C++静态成员函数的生命周期假如我如下定义一个类class temp{public:static void struct(){tempt1}~temp()

C++静态成员函数的生命周期
假如我如下定义一个类
class temp
{
public:
    static void struct(){
        temp   t1;
    }
    
    ~temp(){
        delete p;
    }
private:
    char *p;
    temp(){
        p = new char[10];
    }
}

然后这样调用它
temp::struct();

这样的用法,就是通过类的静态成员函数声明类(专业术语不记得了)
请问,指针p、什么情况下会被释放? C++?静态成员函数
[解决办法]
static void struct(){
        temp   t1;
    }
temp::struct();

这个是函数退出马上释放了。

热点排行