大家帮忙看看这个程序!!
#include<iostream>
#include<cstring>
using namespace std;
class Person
{
public:
Person(){}
Person(const char* n, const char* s, const int a)
{
name = new char[strlen(n)+1];
strcpy(name,n);
sex = new char[strlen(s)+1];
strcpy(sex,s);
age = a;
}
void print() const
{
cout<<"Name:"<<name
<<"Sex:"<<sex
<<"Age:"<<age<<endl;
}
~Person()
{
delete [] name;
delete [] sex;
}
protected:
char* name;
char* sex;
int age;
};
void main()
{
Person person("wang","男",28);
return;
}
========================================
编译能通过,但为什么没有输出呢?