snake5:
I think you are trying to do:
rather thanThough the first way looks much shorter, and it would work if the 'const' keyword were removed, there is a reason that the second way is preferred, and indeed, enforced.
The problem is, for the former code to work, it oblidges myShape->GetFilterData to return the actual filter data object that it is using, rather than a copy. Otherwise, you wouldn't be changing anything permanent with the assignation. But once you are returning the actual private variable of shape, m_filter, there is little point wrapping it in a Get/Set function, you might as well just expose it as public. The whole point of using functions for a public interface is that it hides the internal implementation from view. With the latter code, you can change as much behind the scenes as you like, say removing the filter data object entirely, and it
A similar issues applies to vectors. You should get the same error messages if you tried body->GetPosition().x=100; and for good reason.
I think you are trying to do:
Code: Select all
myShape->GetFilterData().groupIndex=newValue;
myWorld->Refilter(myShape);Code: Select all
dmFilterData filter = myShape->GetFilterData();
filter.groupIndex = newValue;
myShape->SetFilterData(filter):
myWorld->Refilter(myShape);The problem is, for the former code to work, it oblidges myShape->GetFilterData to return the actual filter data object that it is using, rather than a copy. Otherwise, you wouldn't be changing anything permanent with the assignation. But once you are returning the actual private variable of shape, m_filter, there is little point wrapping it in a Get/Set function, you might as well just expose it as public. The whole point of using functions for a public interface is that it hides the internal implementation from view. With the latter code, you can change as much behind the scenes as you like, say removing the filter data object entirely, and it
A similar issues applies to vectors. You should get the same error messages if you tried body->GetPosition().x=100; and for good reason.