W
Wilson
hi, i am trying to understand virtual functions, both how to create
them and how or when to use them - how they can be used to improve a
program. Below is a very simple program which i quickly made using
information gathered from a book on the subject, however this simply
returns a blank space. please help both on this program and anything
else related to virtual functions.
wilson
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
class account
{
public:
int balance, number;
int function() { cout << balance; }
};
class checking : public account
{
public:
int balancechecking;
};
class savings : public account
{
public:
int balancesavings;
};
void display(account& x)
{
x.function();
}
int main()
{
savings a;
checking b;
b.balance = 10;
a.balance = 20;
display(a);
cout << endl;
display(b);
system("PAUSE");
}
them and how or when to use them - how they can be used to improve a
program. Below is a very simple program which i quickly made using
information gathered from a book on the subject, however this simply
returns a blank space. please help both on this program and anything
else related to virtual functions.
wilson
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
class account
{
public:
int balance, number;
int function() { cout << balance; }
};
class checking : public account
{
public:
int balancechecking;
};
class savings : public account
{
public:
int balancesavings;
};
void display(account& x)
{
x.function();
}
int main()
{
savings a;
checking b;
b.balance = 10;
a.balance = 20;
display(a);
cout << endl;
display(b);
system("PAUSE");
}