4 Replies - 1773 Views - Last Post: 10 December 2012 - 12:38 PM Rate Topic: -----

#1 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 78
  • View blog
  • Posts: 1,358
  • Joined: 28-March 09

passing "" as 'this' argument discards qualifiers

Posted 07 December 2012 - 02:04 AM

Hey all, seems as though I can't quite figure this error out, been at it for a bit and my eyes may just be tired.

I receive this error:
error: passing ‘const simphys::Quaternion’ as ‘this’ argument of ‘void simphys::Quaternion::normalize()’ discards qualifiers [-fpermissive]


And my code is this:
mat33 simphys::Quaternion::getMatrix() const
	{
		if(norm() != 1.0f)
			normalize();
 		
 		/* Var declarations make mat33 instantiation cleaner looking */
 		float x0 = ( 1.0f - 2.0f*powf(getQY(), 2) - 2.0f*powf(getQZ(),2) );
 		float y0 = ( 2.0f*getQX()*getQY() - 2.0f*getQZ()*getQW() );
 		float z0 = ( 2.0f*getQX()*getQZ() + 2.0f*getQY()*getQW() );
 		float x1 = ( 2.0f*getQX()*getQY() + 2.0f*getQZ()*getQW() );
 		float y1 = ( 1.0f - 2.0f*powf(getQX(), 2) - 2.0f*powf(getQZ(), 2) );
 		float z1 = ( 2.0f*getQY()*getQZ() - 2.0f*getQX()*getQW() );
 		float x2 = ( 1.0f*getQX()*getQZ() - 2.0f*getQY()*getQW() );
 		float y2 = ( 2.0f*getQY()*getQZ() + 2.0f*getQX()*getQW() );
 		float z2 = ( 1.0f - 2.0f*powf(getQX(), 2) - 2.0f*powf(getQY(), 2) );
 		
 		/* See, pretty matrix :D/>/> */
 		mat33 matrix(x0, y0, z0,
 					 x1, y1, z1,
 					 x2, y2, z2);
		return matrix;
	}


void simphys::Quaternion::normalize()
	{
		if(norm() == 1.0f)
			return;
		else
		{
			float n = norm();
			/* Create a normalized quaternion */
			setQX(getQX() / n);
			setQY(getQY() / n);
			setQZ(getQZ() / n);
			setQW(getQW() / n);
		}
	}



IDK why I receive this error... Anyone know why this is happening?

This post has been edited by IngeniousHax: 07 December 2012 - 02:06 AM


Is This A Good Question/Topic? 0
  • +

Replies To: passing "" as 'this' argument discards qualifiers

#2 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: passing "" as 'this' argument discards qualifiers

Posted 07 December 2012 - 03:10 AM

How will you return the matrix, if you have a void function?
Was This Post Helpful? 0
  • +
  • -

#3 jimblumberg  Icon User is offline

  • member icon


Reputation: 4074
  • View blog
  • Posts: 12,568
  • Joined: 25-December 09

Re: passing "" as 'this' argument discards qualifiers

Posted 07 December 2012 - 06:57 AM

You need to show how you defined this function. But the following error message seems to show a const correctness issue.

Quote

error: passing ‘const simphys::Quaternion’ as ‘this’ argument of ‘void simphys::Quaternion::normalize()’ discards qualifiers [-fpermissive]


Jim
Was This Post Helpful? 0
  • +
  • -

#4 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 78
  • View blog
  • Posts: 1,358
  • Joined: 28-March 09

Re: passing "" as 'this' argument discards qualifiers

Posted 10 December 2012 - 12:34 PM

You were absolutely right jim, I needed to make a copy of the object and than do my operations on the copy instead of the original.

@Adak: I wasn't returning anything in the void function, only in the mat33 return type function. I was modifying the values directly in the void function.
Was This Post Helpful? 0
  • +
  • -

#5 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 662
  • View blog
  • Posts: 2,273
  • Joined: 31-December 10

Re: passing "" as 'this' argument discards qualifiers

Posted 10 December 2012 - 12:38 PM

Because the function:
mat33 simphys::Quaternion::getMatrix() const


is const, you can't modify the class inside the function. You call normalize() inside the function which is not a const function.

Another way to fix the problem is to make normalize() a const function, and then any class data members that are changed inside the normalize() function should have their declarations changed so that they are mutable, example:
mutable int i;

This post has been edited by vividexstance: 10 December 2012 - 12:39 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1