欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

VisualStudio類(lèi)文件的管理(類(lèi)文件的分離)的實(shí)現(xiàn)

 更新時(shí)間:2024年03月08日 11:01:12   作者:Austin_1024  
在使用?Visual?Studio?開(kāi)發(fā)項(xiàng)目的時(shí)候,學(xué)會(huì)進(jìn)行“類(lèi)文件的分離”十分重要,本文主要介紹了VisualStudio類(lèi)文件的管理(類(lèi)文件的分離)的實(shí)現(xiàn),感興趣的可以了解一下

一、問(wèn)題背景

實(shí)際開(kāi)發(fā)中,類(lèi)的聲明放在頭文件中,給程序員看類(lèi)的成員和方法。比如:Dog.h(類(lèi)的聲明文件)

類(lèi)的成員函數(shù)的具體實(shí)現(xiàn),保存在 .cpp 文件中。比如:Dog.cpp(類(lèi)的方法文件)

其他文件,如果需要使用這個(gè)類(lèi),就包含這個(gè)類(lèi)的頭文件。比如:test.h

二、項(xiàng)目文件結(jié)構(gòu)

一圖勝千言,解釋放后面:

類(lèi)的聲明 Dog.h 放在頭文件目錄中, 類(lèi)的成員函數(shù)的實(shí)現(xiàn)放在源文件目錄下的 Dog.cpp 文件中,test.cpp 是用來(lái)放測(cè)試代碼的文件。

二、代碼

1、Dog.h的代碼

#pragma once

#include <string>

using namespace std;

//類(lèi)的聲明文件
class Dog{
private:
	string name;
	int age;
public:
	Dog(string name, int age);
	void sleep();
	void eat();
	void say();
};

2、Dog.cpp的代碼

//類(lèi)的具體實(shí)現(xiàn):用來(lái)實(shí)現(xiàn)類(lèi)Dog的具體方法

#include "Dog.h"
#include <iostream>
#include <string>

using namespace std;

Dog::Dog(string name, int age) {
	this->name = name;
	this->age = age;
}

void Dog::eat() {
	cout << "吃飯啦" << endl;
}

void Dog::sleep() {
	cout << "睡覺(jué)啦" << endl;
}

void Dog::say() {
	cout << this->name << endl;
	cout << this->age << endl;
}

3、test.cpp的代碼

#include <iostream>
#include "Dog.h"

using namespace std;

int main() {
	Dog dog("旺仔", 3);//創(chuàng)建Dog對(duì)象
	dog.eat();//輸出 吃飯啦
	dog.sleep();//輸出 睡覺(jué)啦
	dog.say();//輸出 旺仔 3

	system("pause");
	return 0;
}

三、運(yùn)行截圖

四、總結(jié)

在使用 Visual Studio 開(kāi)發(fā)項(xiàng)目的時(shí)候,學(xué)會(huì)進(jìn)行“類(lèi)文件的分離”十分重要。這會(huì)幫助開(kāi)發(fā)者管理項(xiàng)目更加輕松。

實(shí)際開(kāi)發(fā)中,類(lèi)的聲明放在頭文件中,給程序員看類(lèi)的成員和方法。比如:Dog.h(類(lèi)的聲明文件)

類(lèi)的成員函數(shù)的具體實(shí)現(xiàn),保存在 .cpp 文件中。比如:Dog.cpp(類(lèi)的方法文件)

其他文件,如果需要使用這個(gè)類(lèi),就包含這個(gè)類(lèi)的頭文件。比如:test.h

到此這篇關(guān)于VisualStudio類(lèi)文件的管理(類(lèi)文件的分離)的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)VS類(lèi)文件管理內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論