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

程序改动

shaoyuan 发布于 2008-09-20 09:29, 440 次点击
#include <iostream>      
using namespace std;
class Internet  
{  
    public:  
        Internet(char *name,char *ur1)  
        {
            Internet::name = new char[strlen(name)+1];  
            Internet::url =new char[strlen(ur1)+1];
            if(name)
            {  
                strcpy(Internet::name,name);  
            }  
            if(url)
            {  
                strcpy(Internet::url,ur1);
            }
        }
    public:  
        char *name;
        char *url;  
};
int main()  
{   
    Internet a("中国软件开发实验室",");
    system("parse");
}
上面的程序中把Internet::url =new char[strlen(ur1)+1];改成Internet::url =ur1;有什么不妥吗?
1 回复
#2
xxhxiang2008-09-20 09:54
这个ur1可能是一个临时指针,他销毁后Internet::url就没有定义了
1