/*https://blog.csdn.net/xulingxin/article/details/81335030*/ /*视频:https://www.bilibili.com/video/BV1KC4y1a7S1?from=search&seid=17670598384643769000*/ /*类的定义与实现*/ /*类内定义函数成员*/ /*#include<bits/stdc++.h> using namespace std; class point{ public ://表示该部分内容是私密的,不能被外部访问 //或者直接调用 void setpoint(int x,int y) { xpos=x; ypos=y; } void printpoint() { cout<<"x= "<<xpos<<' '; cout<<"y= "<<ypos<<' '; } private ://公开的属性和方法,外界可以直接访问或调用 int xpos; int ypos; }; int main() { point m; m.setpoint(10,20); m.printpoint() ; return 0; }*/ /*类外定义函数成员*/ #include<bits/stdc++.h> using namespace std; class point{ public : void setpoint(int x,int y); void printpoint(); private : int xpos; int ypos; }; void point::setpoint(int x,int y) { xpos=x; ypos=y; } void point::printpoint() { cout<<xpos<<' '; cout<<ypos<<' '; } int main() { point m; m.setpoint(10,120); m.printpoint() ; return 0; }