Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: I am trying to store a transform for future reference but I am having trouble.  (Read 2873 times)

0 Members and 1 Guest are viewing this topic.

Critkeeper

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
This is my line of code:

Code: [Select]
absoluteTransform = states.transform *= this->getTransform();
states is of type sf::RenderStates.

"this" is a pointer to an object that inherits from sf::Transformable

my error is

Code: [Select]
passing 'const sf::Transform' as 'this' argument of 'sf::Transform& sf::Transform::operator=(const sf::Transform&)' discards qualifiers

I feel like I am missing something fundamental that should be obvious to me. I read the API for transform and the sf::Transform::operator= isn't even defined! Yet, this error is telling me that this operator is defined!

I know what I want to do. I want to store the states.transform for future reference. I just don't know how. I know that "qualifiers" refers to the const-ness of the argument but I don't understand how that is relevant or how it could be relevant. It would be easier if I knew for a fact that I could overwrite the state of one Transform with the state of another, but I am unsure if I can even do that because there is nothing in the API that would suggest that I can. And yet, if I cannot, then I cannot store any Transform and that seems absurd.

In case you are wondering why I need to store it in the first place, I don't think that is relevant to the discussion here because I am not looking for any workaround. If I really can't store an arbitrary transform then something is very wrong with my understanding and a workaround won't fix that.
« Last Edit: January 01, 2015, 02:30:23 am by Critkeeper »
if(CritKeeper.askQuestion()){return question.why();}

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
C++ compilers generate assignment operator on their own if there is no custom one.
Your 'absoluteTransform' is just const.
Is it a variable of a class and are you trying to assign it in a const method(SFML's draw maybe)?
Back to C++ gamedev with SFML in May 2023

Critkeeper

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Yes it is a member declared privately as:

Code: [Select]
sf::Transform absoluteTransform;
And you are correct I am trying to define SFML's draw for a specific type of scene node.
if(CritKeeper.askQuestion()){return question.why();}

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
It's a const method so it can't modify members... this is core C++ stuff, not SFML specific.
Back to C++ gamedev with SFML in May 2023

Critkeeper

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
I'm sorry for wasting your time then I will study up on it. I knew I was missing something fundamental. Seems kind of sad I can have had a year of software engineering and never have been exposed to the const keyword used in that manner.

In the meantime so I know in what general direction to focus my effort, I am not wrong in assuming that I can store a Transform, right? I mean, it seems silly to think that I can't, even if doing it the way I tried to do it is erroneous.
if(CritKeeper.askQuestion()){return question.why();}

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Yes, you can have a variable of type sf::Transform and assign to it as long as its not const.  A transform is much like a vector2 in that it's just a bunch of numbers, so it has the same intuitive value semantics you'd expect of an int or any other fundamental type.

Raincode

  • Full Member
  • ***
  • Posts: 118
    • View Profile
I believe adding the mutable keyword will allow const member functions to modify your transfrom member. Not sure though...
I just looked it up a day ago after reading it in some source, so I thought I'd throw it in here.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Quote
I believe adding the mutable keyword will allow const member functions to modify your transfrom member.
You can always work around technical limitations. But they are there for a reason, not just to bother developers... ;)
Laurent Gomila - SFML developer