菜鸟求解
- #include<iostream>
- #include <stdio.h>
- class Sequence{
- public:
- Sequence(int count=10,string name = "abc");
- void show();
- ~Sequence();
-
- int* _content;
- int _count;
- string _name;
-
- };
-
- Sequence::Sequence(int count,string name){
- _count = count;
- _content=new int[count];
- _name = name;
- for(int i=0;i<count;i++){
- _content[i]=i;
- }
- this->show();
- cout<<"constructor over!!"<<endl;
- }
-
- Sequence::~Sequence(){
- cout << "execute ---"<<_name;
- delete [] _content;
- }
-
- void Sequence::show(){
- cout<<endl<<"{";
- for(int i=0;i<_count;i++){
- cout<<_content[i]<<" ";
- }
- cout<<"name = "<<_name<<endl;
- cout<<"}"<<endl;
- }
-
- int main(){
- Sequence s1;//这里有疑问,运行结果并没有调用析构函数,为啥啊?
- //s1.~Sequence();
- //s1.show();
- //s1.~Sequence();
- //s1.show();
- //s1 = Sequence(3,"s1");
- //s1.show();
- //Sequence(5,"hello");
- system("pause");
- }
作者: qwerboo 发布时间: 2011-06-14
....
void test()
{
Sequence s1;
}
int main(){
test();
system("pause");
}
...
void test()
{
Sequence s1;
}
int main(){
test();
system("pause");
}
...
作者: int-main 发布时间: 2011-06-14
哇 果然正确了 但是为啥啊? 能讲下嘛,或者推荐一本书看看,谢谢了!
作者: qwerboo 发布时间: 2011-06-14
C++对象模型
作者: int-main 发布时间: 2011-06-14