C++ problems

Hi, I'm working on some C++ projects and was having some problems, any help would be greatly appreciated.


First issue,

class Mortgage{
private :
double principal ; // amount
double apr ; // annual rate
int term ; // terms in number of month
double payment ; // monthly payment

public :

// accessors
double get_principal() ;
double get_apr () ;
double get_payment() ;
int get_term() ;
double calc_payment(); //calculate monthly payment
// print the mortgage payment table
void printTable();
// print out the summary of the mortgage
void display() ;
// constructors
Mortgage(double principal, double rate , int term) ;
Mortgage(Mortgage & mtg) ; // copy constructor

} ;

Can someone explain why this works even though it doesn't have a destructor and overload assignment operator?


Second, If I changed the Class to this,

class Mortgage{
private :
double *principal ; // amount
double *apr ; // annual rate
int *term ; // terms in number of month
double *payment ; // monthly payment

public :

// accessors
double get_principal() ;
double get_apr () ;
double get_payment() ;
int get_term() ;
double calc_payment(); //calculate monthly payment
// print the mortgage payment table
void printTable();
// print out the summary of the mortgage
void display() ;
// constructors
Mortgage(double principal, double rate , int term) ;
Mortgage(Mortgage & mtg) ; // copy constructor

} ;


all the corresponding functions and constructors are implemented correctly, and I have done the necessary changes in my .cpp file, will my .cpp still work the properly?
Help?
The first class looks fine. I believe the compilers create default destructors. Why would you need an overload assignment operator?

Using pointers in the second declaration makes less sense, as you'd then have to create space for the variable.
Topic archived. No new replies allowed.