c++关于类的练习

#include<iostream>

#include<string.h>

using namespace std;

class CPerson

{

private:

char name[12];

int age;

float height;

long friendID;

int IsMyFriend(long fid);

public:

void PubPrivate(long fid);

void SetPrivate(char *n = " ", int a = 0, float h = 0);

void SetFriendID(long fid = 12345);

};

int CPerson::IsMyFriend(long fid)

{

return fid == friendID ? 1 : 0;

}

void CPerson::PubPrivate(long fid)

{

cout << "hello" << endl;

if (IsMyFriend(fid))

cout << "My friend:I am " << name

<< "," << age << " years old,and my height is " << height << endl;

else

cout << "Sorry,you are not my friend" << endl;

}

void CPerson::SetPrivate(char *n, int a, float h)

{

strcpy(name, n);

age = a;

height = h;

}

void CPerson::SetFriendID(long fid)

{

friendID = fid;

}

void main(void)

{

CPerson me, *pme = &me;

(*pme).SetPrivate("Tom", 18, 185);

pme->SetFriendID(45678);

me.PubPrivate(4567);

(*pme).PubPrivate(45678);

cout << sizeof(CPerson) << endl;

system("pause");

}

问题是无法调试

为啥有昵称
浏览 1346回答 2
2回答

__YXQ__

把strcpy换成stycpy_s?

慕瓜9220888

ZQPAPSSVECCODFIRBXDVXPDNKJGEFEPEYHNNKCFOTMSIYWUPUYILKKQKPHQQUHAWOZOGBLLBLPHNYOBDPSTVHFPCOOAOBDMDTGRUVGPTQGWJXSNFDGTZGXSXPBUUGQBVEFBXQQTSMBTSPYYBDKCUQCPPCOTRDCFRHOFJIWIOLOBIGBNCILRAYMEJLUAAXZHTHTDWSCPUTIYIFWFVRZLDNQWIAHNGYYLBXSQLGZVEEJSPHGOBRKXFNSXPMMQGVJHDOJJIIQXTSKDOOXEZUGORAAQWLHCEBKNTTLGVXXDDZBIHIHKXXTYCUWBYRXAIQOXZPSYYLJHQIBOWIBWHHGJJYXEKGYPIUBERFCUCMZSLNSVNTZZCVRTITVWQGHPXPHMVINDLIORWMMJZNLQCBOEHRHYKCHATCZKIKCYVVLEQYZFDGJKRASDVKUQAOJRMRAMJCWMUCLMWPFCGNVOWWZSIDETLKNQGGJBSBAEEVPCMVWBVC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