Richard Topchii
Richard Topchii

Reputation: 8195

NSInteger multiplication: Invalid operands to binary expression

I try to multiply two NSIntegers, but Xcode gives me an error:

NSInteger singlePage = ((NSInteger)floor((scrollView.contentOffset.x * 2.0f + pageWidth) / (pageWidth * 2.0f)));
NSInteger page = singlePage * visiblePages;  

And the error itself:

Invalid operands to binary expression ('NSInteger' (aka 'int') and 'NSInteger *' (aka 'int *'))  

NSInteger visiblePages is already defined and is being passed to a method.
I think that the compiler thinks that the * is a pointer sign and not a multiplication symbol. Is there any other method to multiply two NSIntegers?

Upvotes: 2

Views: 2477

Answers (1)

Sviatoslav Yakymiv
Sviatoslav Yakymiv

Reputation: 7935

You defined visiblePages incorrectly. Replace

NSInteger *visiblePages;

with

NSInteger visiblePages;

Upvotes: 7

Related Questions