Incompatible parameter type

I'm doing classes for my assignment and the example we were given did not deal with int's and double's, but the assignment does. I've gotten to the point where I'm defining the class but I don't know how to define the int's and double's in the arguments. I get the error "C++ default argument of type is incompatible with parameter of type". I'm not sure how or what I should put to fix the error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <string>
using namespace std;

class bankAccount
{
public:
	void print() const;
	void setName(string name);
	void setType(string type);
	void setAccNum(int num);
	void setBal(double bal);
	void setRate(double rate); //decimal

	bool isFullName(string name) const;
	bool isAccType(string type) const;
	bool isAccNum(int num) const;
	bool isAccBal(double bal) const;
	bool isInterestRate(double rate) const;

	string getFullName() const;
	string getAccType() const;
	int getAccNum() const;
	double getAccBal() const;
	double getInterestRate() const;

	bankAccount(string name = "", string type = "", int num = "", double bal = "", double rate = ""); //The error is here. I know I cannot put "" after the numbers, but I dont know what to put instead.

private:
	string fullName;
	string accType;
	int accNum;
	double accBal;
	double interestRate;

};
Hello rovert456,

Since you did not include the whole error message I am guessing that it might refer to this: void setType(string type); and bool isAccType(string type) const;. Although "type" is not a reserved keyword it may still be causing a problem.

So unless the problem is where you defined the functions, i.e., the forward declaration in the class does not match the function definition, it is hard to say because what is in the class looks OK right now.


It is best to include enough of the program that can be compiled.

Andy
Hello rovert456,

Sorry I did not see the comment hiding off to the right.

You know that (int num = "") is wrong, so what does an int hold? What does a double hold? I hope that you know this?

Andy
Hello Andy,

I have absolutely no clue, that's why I'm asking for help. What do you mean by hold? I know that the the range of an int is +-2147483647 if thats what you mean. If I left it as (int num) I would just get the error "default argument not at end of parameter list"
= 0.0 for double
= 0 for int
Thank you seeplus, I appreciate the answer
Hello rovert456,

Sorry about that I should have been more clear.

You know that (int num = "") is wrong, so what does an int hold?
An int holds a whole number whereas a "double" holds a floating point number.

Your code:
bankAccount(string name = "", string type = "", int num = "", double bal = "", double rate = ""); is designed to set a default value for the variables, so what default value do you need for the "int" and "double"s?

If I left it as (int num) I would just get the error "default argument not at end of parameter list"
. When using default values they work from right to left. The last variable must have a default before you can give the next to last a default value. and do on. And if the first parameter needs a default value then all parameters must have a default value.

Andy
Topic archived. No new replies allowed.