C++分文件写法

1.创建.h后缀头文件

  头文件中写函数声明

  引用是用#include".h"

  #pragma once//防止头文件被重复包含

  例(点类):

 1 #pragma once
 2 #include<cstdio>
 3 #include<iostream>
 4 using namespace std;
 5 
 6 class Point
 7 {
 8 private:
 9     int x,y;
10 public:
11     void set(int tx,int ty);
12     pair<int,int> get();
13 };  
View Code

 

2.创建.cpp后缀源文件

  源文件中写函数内容

  对于成员函数,写出定义域 ::

1 #include"point.h"
2  
3 void Point::set(int tx,int ty){x=tx;y=ty;}
4 pair<int,int> Point::get(){return make_pair(x,y);}
View Code

 

posted @ 2021-08-06 10:08  Al_Ca  阅读(156)  评论(0编辑  收藏  举报
ヾ(≧O≦)〃嗷~