No data conversion possible ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
struct BigIntP {
private:
	BigInt numer;
	BigInt denom;

public:
...
operator BigInt() { 
	return numer/denom;
}

void BigIntP::operator = (BigInt a) {
	numer=a;
	denom=1;
}

void BigIntP::operator += (BigInt a) {
	BigIntP c=a;
	*this=*this+c;
}
...
}

I have this code and for line 18 it is telling me that no suitable user-conversion from "BigInt" to "BigIntP" exists
It als gives this error for that line:
error C2440: 'initializing' : cannot convert from 'BigInt' to 'BigIntP'
1>          No constructor could take the source type, or constructor overload resolution was ambiguous

Can someone tell me what is going wrong ? Because as far as I know I did define a data conversion between those 2.
Last edited on
closed account (Dy7SLyTq)
you are trying to convert a BigInt to a BigIntP which you have no code for
I thought that this converted from BigInt to BigIntP ?

1
2
3
4
void BigIntP::operator = (BigInt a) {
	numer=a;
	denom=1;
}
I added this constructor to my code and it works now. But I still don't understand why it didn't work. It would be nice if someone could explain that to me.
 
BigIntP(BigInt a) {*this=a;}
In this line

BigIntP c=a;

a copy constructor is used. You did not show in your original post how the copy constructor is defined.

Edit: I am sorry. I have seen only now that there are two types

BigIntP and BigInt

in your code snip.

So it is obvious that your class BigIntP had no constructor that has parameter of type BigInt.
Last edited on
Topic archived. No new replies allowed.