- Joined
- Feb 2, 2012
- Messages
- 1,667
- Reaction score
- 115
- Points
- 78
Hi guys,
I've been working a bit in these days and I have the following doubt.
Let's say that I am making a project and that I also make the relevant APIs and SDK for others to use it.
Let's also say that I want to put Handles made by myself in it. Actually it is not the case but I am in the exact position of implementing this and I am willing to learn how to properly do it.
The thing I am working on is a linking system between vessels which will behave phisically like docking but with the commands and hierarchy of attachments.
So I have a std::vector holding the list of all the links in the sim which are processed at every frame.
The links are identified by a unique index, which never changes during runtime and that never duplicates.
So if I want to identify the link I can refer to its index, which means (to my eyes) that the index is the best candidate for a linkhandle here.
So I made the linkAPI.h which basically just contains
and then when I pass the linkhandle in the process the handle gets casted back to integer to get the index.
The issue I am encountering is relevant to the void* pointer and to pointers in general... for example in a function if I try to use the static_cast it doesn't work:
the compiler says that this conversion of type is not valid and my guess is that because void* is a pointer while int is not.
if I change it to
then the conversion works, but I don't want a pointer to an integer, I want an integer to use so it seems not useful to me (even if I realize that pointers can work also this way if only I could get it...)
but to my surprise this works fine even though my feel is that it's not right:
So... what's the proper way to do it?
thanks in advance to anyone!
I've been working a bit in these days and I have the following doubt.
Let's say that I am making a project and that I also make the relevant APIs and SDK for others to use it.
Let's also say that I want to put Handles made by myself in it. Actually it is not the case but I am in the exact position of implementing this and I am willing to learn how to properly do it.
The thing I am working on is a linking system between vessels which will behave phisically like docking but with the commands and hierarchy of attachments.
So I have a std::vector holding the list of all the links in the sim which are processed at every frame.
The links are identified by a unique index, which never changes during runtime and that never duplicates.
So if I want to identify the link I can refer to its index, which means (to my eyes) that the index is the best candidate for a linkhandle here.
So I made the linkAPI.h which basically just contains
Code:
typedef void* LINKHANDLE;
and then when I pass the linkhandle in the process the handle gets casted back to integer to get the index.
The issue I am encountering is relevant to the void* pointer and to pointers in general... for example in a function if I try to use the static_cast it doesn't work:
Code:
bool LinkManager::ActivateLink(LINKHANDLE lh) {
int index = static_cast <int>(lh);
...
...
return FALSE;
}
the compiler says that this conversion of type is not valid and my guess is that because void* is a pointer while int is not.
if I change it to
Code:
int* index = static_cast <int*>(lh);
then the conversion works, but I don't want a pointer to an integer, I want an integer to use so it seems not useful to me (even if I realize that pointers can work also this way if only I could get it...)
but to my surprise this works fine even though my feel is that it's not right:
Code:
bool LinkManager::ActivateLink(LINKHANDLE lh) {
int index = (int)lh;
...
...
return FALSE;
}
So... what's the proper way to do it?
thanks in advance to anyone!
