当前位置:网站首页>2022/02/12

2022/02/12

2022-07-06 18:19:00 ekkoxxxx

Constructors : Because the data members of a class cannot be initialized when the class is declared , So the constructor is introduced to initialize . Grammatical features : no return value .

publicTest()
		{
    
		}

Destructor : Contrary to constructors , When out of scope , Automatic execution of destructors , For example, free the memory in the heap . Constructors can have multiple , There is only one destructor , Grammatical features : Again, there is no return value .

~Test()
{
    
}

overloaded function : When writing code, you often encounter some functions with the same function but different details , For example, the function of adding two numbers Add, But it is not clear that the two numbers are int,double,float What kind of , Therefore, overloaded functions are introduced to facilitate code writing .

#include<iostream>
#include<Windows.h>
using namespace std;

int Add(int a, int b)
{
    
	return a + b;
}
 
double Add(double a, double b)
{
    
	return a + b;
}
 
float Add(float a, float b)
{
    
	return a + b;
}
int main()
{
    
	cout<<Add(1,2)<<endl;
	cout<<Add(3.4, 5.6)<<endl;
	cout << Add(2.34, 3.45) << endl;
	system("pause");
	return 0;
}

原网站

版权声明
本文为[ekkoxxxx]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131300386624.html