expression must have a pointer-to-member type

Mar 6, 2014 at 3:49am
I created a class called Polynomial that asks the user for coefficients and exponent. I also created a function that would add the two polynomials.
I'm stuck on how to access my pointer arrays from an instance and different objects.
I dont understand why i get an error at temp.*(p+i) and op.*(p + i) "expression must have a pointer-to-member type". Please help!

1
2
3
4
5
6
7
8
9
Polynomial Polynomial::operator+(Polynomial op) 
{
	Polynomial temp;
	for(int i = 0; i < SIZE; i++)
	{
		temp.*(p+i) =  *(p + i) + op.*(p + i); //stuck here
        }
	return temp;
}


If additional code is needed, I would be happy to provide them.
Mar 6, 2014 at 4:28am
*(temp.p + i) = *(p + i) + *(op.p + i);

Or I suppose you could just do
temp.p[i] = p[i] + op.p[i];.
Mar 6, 2014 at 5:46am
That works... But I was wondering how it would work if I were to use pointers rather instead.
Mar 6, 2014 at 6:00am
The first line of code that he posted does that?
Mar 6, 2014 at 7:54am
The first line of code that he posted does that?


So does the second.
Topic archived. No new replies allowed.