Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Conversion Operator Problem (http://www.go4expert.com/forums/conversion-operator-problem-t5683/)

Peter_APIIT 5Aug2007 13:20

Conversion Operator Problem
 
Hello all expert C++ programmer, i truly new to C++ programming.

I have a exercise where need to calculate the monthly interest with the balance supplied.

Header File:

Code:

#pragma once

class savingAccount
{
        static double annualInterestRate;
        double balance;
        double monthlyInterest;
public:
        savingAccount() : balance(0), monthlyInterest(0){}
        explicit savingAccount(double balance, double monthlyInterest)
                :balance(balance), monthlyInterest(monthlyInterest){}
       
        void calMonthlyInterest();
    static void modifyInterestRate();

        ~savingAccount(){}
};


/* Static data member cannot initialized
  by constructor
*/

Implementation File:



Code:

#include<iostream>
#include<cstdlib>
#include "Saving Account.h"

using std::cout;
using namespace std;

double savingAccount::annualInterestRate = 0.05;

int main(int argc, char *argv[])
{
        savingAccount peter(2000);
        savingAccount nicholas_tse(3000);
   
        peter.calMonthlyInterest();

        return EXIT_SUCCESS;
}
// -----------------------------------------
void savingAccount::calMonthlyInterest()
{
        monthlyInterest = (balance * annualInterestRate)/12;
}
// -----------------------------------------


Error Message :

Quote:


Error 1 error C2664: 'savingAccount::savingAccount(const savingAccount &)' : cannot convert parameter 1 from 'int' to 'const savingAccount &' d:\c++\saving account\saving account\saving account.cpp 12
Error 2 error C2664: 'savingAccount::savingAccount(const savingAccount &)' : cannot convert parameter 1 from 'int' to 'const savingAccount &' d:\c++\saving account\saving account\saving account.cpp 13


I hope someone cna help me out.

Thanks for your help.

Your help is greatly appreciated by me and others.

shabbir 5Aug2007 20:56

Re: Conversion Operator Problem
 
I cannot understand what you are trying to do. I don't see any one parameter constructor for your class savingAccount but your error suggest it has one with a const parameter. If thats the case convert your int parameter into const int

Peter_APIIT 6Aug2007 12:08

Re: Conversion Operator Problem
 
I have set the one of the constructor explicit where to enhance one argument is been supplied.

shabbir 6Aug2007 15:19

Re: Conversion Operator Problem
 
Quote:

Originally Posted by Peter_APIIT
I have set the one of the constructor explicit where to enhance one argument is been supplied.

What is the signature of that constructor?

it career 6Aug2007 19:09

Re: Conversion Operator Problem
 
What is the reason of having explicit constructor?
Where is the defintion of constructor corresponding to
Code:

savingAccount peter(2000);

seeguna 7Aug2007 09:55

Re: Conversion Operator Problem
 
No definition for Single argument constructor in ur program

If u want a simple solution means
add the following line to ur header file

savingAccount(double balance):balance(balance){}


so that u got an answer...........


All times are GMT +5.5. The time now is 06:08.