类的分文件编写
point.h
1、在开头加上以下代码
#pragma once
//防止头文件重复包含
#include<iostream>
using namespace std;
2、将Point类复制粘贴到这里,进行修改。将成员函数的函数体删除,只留下函数名,并在后面加上分号(声明函数)。
#pragma once
#include<iostream>
using namespace std
//点类
class point(){
public
//设置x坐标
void setm_x(int x);
int getm_X();
//设置y坐标
void setm_y(int y);
int getm_y()
private
int m_x;
int m_y;
}
}
point.h
1、在开头加上:#include"point.h"
2、将Point类复制粘贴到这里,进行修改。只留下成员函数,剩下的都删除,并在成员函数名前加上Point::。
3、最终point.cpp为:
#include"point.h"
//设置x坐标
void point::setm_x(int x){
m_x=x;
}
int point::get(){
return m_x
}
void point::setm_y(int y){
m_y=y
}
int point::getm_y(){
return m_y}