想要实现2个结果互换,都是结果没有变。
#pragma once
class people
{
public:
virtual float getCK();//存款
virtual void setput();//输入
virtual void display();//输出
people();
~people();
};
class QFR :public people
{
private:
float j;
float h;
public:
QFR();
float getCK();//存款
void setput();//输入
void display();//输出
~QFR();
};
class QDD :public people
{
private:
float j;
float h;
public:
QDD();
float getCK();//存款
void setput();//输入
void display();//输出
~QDD();
};
#include<iostream>
using namespace std;
#include"b.h"
template<typename T>
void Change(T a,T b)
{
T c;
c = a;
a = b;
b = c;
}
float people::getCK()
{
return 0.0;
}
void people::setput()
{
cout << "NULL" << endl;
}
void people::display()
{
cout << "NULL" << endl;
}
people::people()
{
cout << "people构造函数" << endl;
}
people::~people()
{
cout << "people析构函数" << endl;
}
QFR::QFR()
{
j = 0.0;
h = 0.0;
}
void QFR::setput()
{
cout << "钱夫人基本工资" << endl;
cin >> j;
cout << "钱夫人工作时间" << endl;
cin >> h;
}
float QFR::getCK()
{
return j + h * 60;
}
void QFR::display()
{
cout << "钱夫人基本工资:" << j << endl;
cout << "钱夫人工作时间:" << h << endl;
cout << "钱夫人存款:" << getCK() << endl;
}
QFR::~QFR()
{
cout << "钱夫人析构函数" << endl;
}
QDD::QDD()
{
j = 0.0;
h = 0.0;
}
void QDD::setput()
{
cout << "钱多多基本工资" << endl;
cin >> j;
cout << "钱多多工作时间" << endl;
cin >> h;
}
float QDD::getCK()
{
return j + h * 30;
}
void QDD::display()
{
cout << "钱多多基本工资:" << j << endl;
cout << "钱多多工作时间:" << h << endl;
cout << "钱多多存款:" << getCK() << endl;
}
QDD::~QDD()
{
cout << "钱多多析构函数" << endl;
}
int main()
{
QFR d;
d.setput();
d.getCK();
d.display();
cout << "------------------" << endl;
QDD f;
f.setput();
f.getCK();
f.display();
cout << "------------------" << endl;
Change(f.getCK(), d.getCK());
cout << "钱多多存款:" << f.getCK() << endl;
cout << "钱夫人存款:" << d.getCK() << endl;
}