Conversion Operator Problem

Peter_APIIT's Avatar, Join Date: Apr 2007
Contributor
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.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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
0
Peter_APIIT's Avatar, Join Date: Apr 2007
Contributor
I have set the one of the constructor explicit where to enhance one argument is been supplied.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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?
0
it career's Avatar, Join Date: Apr 2007
Go4Expert Member
What is the reason of having explicit constructor?
Where is the defintion of constructor corresponding to
Code:
savingAccount peter(2000);
0
seeguna's Avatar
Go4Expert Member
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...........