#pragma once
#include<iostream>
#include<string>
class man
{
private:
std::
string name;
int year;
public:
man();
man(
const std::
string a,
int b =
0);
inline void update()
{
name =
"帅", year =
99;
}
void show();
~man();
};
#include<iostream>
#include<string>
#include"1.h"
int main()
{
using namespace std;
man b;
b.show();
{
cout <<
"这里开始在块内" << endl;
man a(
"wd",
27);
a.show();
man b(
"mmmm");
b.show();
b.update();
b.show();
}
cout <<
"这里在块外了" << endl;
system(
"pause");
return 0;
}
#include<iostream>
#include"1.h"
man::man()
{
name =
"\"NO NAME\"";
year =
0;
}
man::man(
const std::
string a,
int b)
{
name = a;
if (b <
0)
{
std::
cout <<
"人不可能小于0岁,因此,设置为0岁" <<
std::endl;
b =
0;
}
else year = b;
}
void man::show()
{
using namespace std;
cout << name <<
" is " << year <<
" years old." << endl;
}
man::~man()
{
std::
cout << name <<
" end." <<
std::endl;
}
转载请注明原文地址: https://ju.6miu.com/read-6465.html