JochiPochi / libfixmath

Automatically exported from code.google.com/p/libfixmath
0 stars 0 forks source link

C++ Fix16 cast operators should be const. #15

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Compile
  Fix16 a(2.0);
  Fix16 b(4.0);
  int16_t c = a+b;

What is the expected output? What do you see instead?
We get the error:
  error: passing ‘const Fix16’ as ‘this’ argument of ‘Fix16::operator int16_t()’ discards qualifiers [-fpermissive]

This code should, IMHO, successfully compile with no warning.
The problem is that the operator+() method returns a const Fix16, on which we 
call operator int16_t() which is not const, and can not apply on that object.

Attached is a (very simple) fix (just setting all cast operators as const).

What version of the product are you using? On what operating system?
Latest svn revision.

Original issue reported on code.google.com by louizat...@gmail.com on 2 Jul 2012 at 4:01

Attachments:

GoogleCodeExporter commented 8 years ago
Agreed and done.

If you find yourself using this project a lot and think you could offer more 
useful patches then I'll gladly set you up as a contributor.

Original comment by Flatmush@googlemail.com on 2 Jul 2012 at 4:09