VS2019的多文件编译方法

方法:

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

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

3.编辑自己新建的文件

4.运行

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

//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;
}

 

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值