THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 19/05/2004 at 16:21, xxxxxxxx wrote:
Cinema 4D Version: 8.206
Platform: Windows ;
Language(s) : C++ ;
Im trying to retrieve an Point Selection Tag from an object via a LINK control in a UI.
Im attempting to get the SelectionTag, if there is none, I am trying to create a new BaseSelect and select all the elements inside.
If there was a SelectTag then Im trying to simply print out the amount of selected elements.
My code is
// Get the Point Selection link from the GUI
bsSelection = (BaseSelect* )data->GetLink(MAIN_LINKPOINTSELECTION, hh->GetDocument());
// If there is no PointSelection Tag, create a new internal one, and populate it
bsSelection = BaseSelect::Alloc();
// Crashes on this line
For some reason, I am crashing when there is a SelectionTag.
Any reason why?
On 19/05/2004 at 16:30, xxxxxxxx wrote:
I just relacing it with
And that printed a number like 285662124 in the conole!
Now im quite sure there arn't that many segments in this selection tag, as the object is only a 4 point polygon, with one point selected
On 20/05/2004 at 03:46, xxxxxxxx wrote:
If you are retrieving a selection from a LINK field the returned type cannot be a BaseSelect. It has to be a SelectionTag.
SelectionTag *stag = ( SelectionTag * )data->GetLink(MAIN_LINKPOINTSELECTION, hh->GetDocument()); if(!stag) return FALSE;
bsSelection = stag->GetBaseSelect();
That´s probably why it´s crashing.
On 20/05/2004 at 04:14, xxxxxxxx wrote:
What Samir says is true. Btw, if you would have used the C++-style static_cast_<_baseselect*_>_(...) instead of the C-style cast, then the compiler would have caught the error.
On 20/05/2004 at 14:51, xxxxxxxx wrote:
Thank you Samir. Got it working now
I must sleep more, I'm having trouble with the most obvious things.
Thank you Mikael, I didn't know the difference between static_cast and just (BaseSelect* ). I had no idea one was C++ and the other was C.
Thats what you get for self teaching C++ or C or whatever C langauge I have learn't
On 20/05/2004 at 18:58, xxxxxxxx wrote:
The old conventional casts are still legal cast operators in C++ (it´s just C-style) but as Mikael already said the new cast operators should be used and they bring some advantages too. Not only that they are much better noticed in your code (not only for yourself but also for tools maybe like grep) but they are also better for the compiler to diagnose mistakes.
For example only the const_cast<T> can be used to cast away the constant of something. If you try to cast away the constant of an object or a pointer with one of the other new cast-operators, this expression will not be compiled.
For completeness, there are 2 other cast operators dynamic_cast<T>, which is i.e. used for safe downcasting, and reinterpret_cast<T> can for example be used to cast between a pointer and a function. But it isn´t used very often (I haven´t used it myself yet).
Ok, now it´s bed time.
On 21/05/2004 at 11:18, xxxxxxxx wrote:
In my current project I am using reinterpret_cast<T>. It was from a snippet I saw on the forums. I didn't *really* understand exactly what it was doing, All I knew was it was casting from one data type to another (in this case, a function* to a Real* ).
Thanks for the heads up, Will have to go looking for some c++ resources like this