// Test1111.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//
#include "stdafx.h"
#include <iostream>
#include <cstring>
using namespace std;
class Person
{
private:
char* name;
int age;
public:
Person(char* myname, int myage)
{
int len = strlen(myname) + 1;
name = new char[len];
strcpy_s(name, 100, myname);
age = myage;
}
Person()
:name(NULL), age(0)
{
cout << "called Person()" << endl;
}
void SetPersonInfo(char* myname, int myage)
{
name = myname;
age = myage;
}
void ShowPersonInfo() const
{
cout << "이름: " << name << ", ";
cout << "나이: " << age << endl;
}
~Person()
{
delete[]name;
cout << " called destructor! " << endl;
}
};
int main()
{
Person* parr[3];
char namestr[100];
int age;
for (int i = 0; i < 3; i++)
{
cout << "이름: ";
cin >> namestr;
cout << "나이: ";
cin >> age;
parr[i] = new Person(namestr, age);
}
parr[0]->ShowPersonInfo();
parr[1]->ShowPersonInfo();
parr[2]->ShowPersonInfo();
delete parr[0];
delete parr[1];
delete parr[2];
return 0;
}
구글링해도 원인을 모르겠네요 으하 개발자
strcpy_s를 strcpy(name, myname); 으로..
얘 VS 쓰고 있어서 strcpy_s 써도 될걸
크래프트님처럼 해서 오류나서 크캬캬 님처럼한거에요 ㅠ