预处理解读

首先,记得关闭“C/C++中的预处理到文件”选项。

点击【生成】按钮后,我得到了若干个相应的.i文件。
把它们修改了一下分别为:Lift.i、Athlete.i、main.i

这里关于为甚么要作个说明,由于原先的预处理文件过于冗长,故适当精简以突出重点内容。
其实处理顺序是一致的,都是逐行处理:遇到#include的地方,则把相关内容单拎出来作个替换。
以Lift.txt为例:
第一句(#line 1 “E:\Repository\Sports\WeightLift\Lift.cpp”)表示这是Lift.cpp中的第一行,由于该行是#include “Lift.h”
因此就把该句话作了替换,简单的说就是逐段替换(从第2行开始一直到第78行都是输出的Lift.h中显示内容)

 略为瞩目的是前面三个#include被替换为353637空行,原因是对应的Lift.h,<string>,<iostream>都被包括过了

第78句(#line 2 “E:\Repository\Sports\WeightLift\Lift.cpp”)表示这是Lift.cpp中的第二行,由于不再有#include类似的宏命令。因此就把该文件中剩余的内容都照抄下来,包括Lift.cpp文件内的空换行到结束。

// Lift.i
#line 1 "E:\\Repository\\Sports\\WeightLift\\Lift.cpp"
#line 1 "E:\\Repository\\Sports\\WeightLift\\Lift.h"
#pragma once
#pragma external_header(push)
#line 1 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\include\\string"

#pragma warning(pop)
#pragma pack(pop)
#line 592 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\include\\string"
#line 593 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\include\\string"
#pragma external_header(pop)

#line 3 "E:\\Repository\\Sports\\WeightLift\\Lift.h"
#pragma external_header(push)
#line 1 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\include\\iostream"
#pragma once

#pragma external_header(push)
#line 1 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\include\\istream"

#pragma once
#pragma external_header(push)
#line 1 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\include\\ostream"


#pragma warning(pop)
#pragma pack(pop)
#line 72 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\include\\iostream"
#line 73 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\include\\iostream"
#pragma external_header(pop)

#line 4 "E:\\Repository\\Sports\\WeightLift\\Lift.h"
#line 1 "E:\\Repository\\Sports\\WeightLift\\Athelete.h"
#pragma once




class Athelete
{
	Lift event;	
	std::string personal;
public:
	Athelete() : personal("weight lifter") {};
	Athelete(std::string name) : personal(name) {};
	void start();
	void start(double);
};

#line 5 "E:\\Repository\\Sports\\WeightLift\\Lift.h"

class Lift
{
	friend class Athelete;
public:
	
	
	Lift() = default;
	Lift(double w, bool isSnatch = false) : weight(w) {
		if (isSnatch)
		{
			name = "抓举";
		}
		else
		{
			name = "挺举";
		}
	}
	std::ostream& background();
private:
	double weight{};	
	std::string name;
	float sit(double);	
	bool stand(double);	
						
};

#line 2 "E:\\Repository\\Sports\\WeightLift\\Lift.cpp"

std::ostream& Lift::background()
{
	std::cout << "项目为:" << name << ", 本次所举的重量为:" << weight;
	
	return std::cout;
}

float Lift::sit(double weight)
{
	
	
	return 0.0f;
}

bool Lift::stand(double)
{
	return true;	
}
// Athelete.i
#line 1 "E:\\Repository\\Sports\\WeightLift\\Athelete.cpp"
#line 1 "E:\\Repository\\Sports\\WeightLift\\Athelete.h"
#pragma once
#line 1 "E:\\Repository\\Sports\\WeightLift\\Lift.h"
#pragma once
#pragma external_header(push)
#line 1 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\include\\string"

#pragma once


#pragma warning(pop)
#pragma pack(pop)
#line 72 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\include\\iostream"
#line 73 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\include\\iostream"
#pragma external_header(pop)
#line 4 "E:\\Repository\\Sports\\WeightLift\\Lift.h"


class Lift
{
	friend class Athelete;
public:
	
	
	Lift() = default;
	Lift(double w, bool isSnatch = false) : weight(w) {
		if (isSnatch)
		{
			name = "抓举";
		}
		else
		{
			name = "挺举";
		}
	}
	std::ostream& background();
private:
	double weight{};	
	std::string name;
	float sit(double);	
	bool stand(double);	
						
};

#line 3 "E:\\Repository\\Sports\\WeightLift\\Athelete.h"



class Athelete
{
	Lift event;	
	std::string personal;
public:
	Athelete() : personal("weight lifter") {};
	Athelete(std::string name) : personal(name) {};
	void start();
	void start(double);
};

#line 2 "E:\\Repository\\Sports\\WeightLift\\Athelete.cpp"

void Athelete::start()
{
	std::cout << "举重开始:" << std::endl;
	event.background();
}

void Athelete::start(double weight)
{
	start();
	event.sit(weight);
}

你可能感兴趣的:(c++,开发语言)