gpt4 book ai didi

C++ 类结构

转载 作者:行者123 更新时间:2023-11-27 23:21:00 25 4
gpt4 key购买 nike

<分区>

这里需要一些指导

我得到了一个代码是

struct Point
{
int x;
int y;
};

然后在我的课上我得到了一个函数

class MyClass
{
private:
Point myPoint[4];
public:
void setPoint();
};

void MyClass::setPoint()
{
int xData,yData;

for (int i=0;i<4;i++)
{
cout << "Please enter x-ordinate:";
cin >> xData;

cout << "Please enter y-ordinate:";
cin >> yData;

//at this part the code throw a segmentation core dump.
myPoint[i].x = xData;
myPoint[i].y = yData;
}

}

在第一次运行时没有任何反应,但在第二次循环中,出现分段核心转储。我的代码有什么问题?

main.cpp 上的附加代码

#include "MyClass.h"

int main()
{
MyClass *mClass;

mclass->setPoint();
}

感谢您的帮助。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com