为什么我的这段程序崩溃了呀
											为什么别人的没有崩溃呢?我感觉我的和别人的一摸一样啊,崩溃代码好像是那个++i另外createMonster这个函数里,返回值是rt,但是rt难道不是一个局部变量吗?怎么返回呢
 程序代码:
程序代码:
 
#include<iostream>
int clen(const char* str)
{
    int i;
    for (int i = 0; str[i]; i++);
    return ++i;
}
char* cstr(const char* str)
{
    int len = clen(str);
    char* strRt = new char[len];
    memcpy(strRt, str, len);
    return strRt;
}
typedef struct Role
{
    char* Name;
    int   Hp;
    int   MaxHp;
    int   Mp;
    int   MaxMp;
    int   Lv;
}*PROLE, ROLE;
ROLE createMonster(const char* str,int Hp,int Mp)
{
    Role rt{ cstr(str), Hp, Hp, Mp, Mp, 1 };
    return rt;
}
int main()
{
    ROLE role = createMonster("abc", 1500, 1500);
    std::cout << role.Name << std::endl;
    std::cout << role.Hp << std::endl;
 
}
										
					
	


 
											





 
	    

 
	