您的位置:首页 > 其它

VS2019的多文件编译方法

2019-07-08 16:29 656 查看

方法:

1.打开VS2019建立一个空项目

2.里面都是空的,在对应目录下新建自己的头文件、源文件

3.编辑自己新建的文件

4.运行

代码(6-3对象数组应用举例的代码):

[code]//main.cpp
#include<iostream>
#include"Point.h"
using namespace std;
int main()
{
cout << "Entering main..." << endl;
Point a[2];
for (int i = 0; i < 2; i++)
a[i].move(i + 10, i + 20);
cout << "Exiting main..." << endl;
return 0;
}

//Point.h
#ifndef _POINT_H
#define _POINT_H
class Point {
public:
Point();
Point(int x, int y);
~Point();
void move(int newX, int newY);
int getX() const { return x; }
int getY() const { return y; }
static void showCount();  //静态成员函数
private:
int x, y; //私有成员
};
#endif//_POINT_H

//Point.cpp
#include<iostream>
#include"Point.h"
using namespace std;
Point::Point() :x(0), y(0) {
cout << "Default Constructor called." << endl;
}
Point::Point(int x, int y) : x(x), y(y) {
cout << "Constructor called." << endl;
}
Point::~Point() {
cout << "Destructor called." << endl;
}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐