typcasting in pointers

I have to typecast following dynamic arrays, to change the int into unsigned char,
I tried in following way but it does not work, please tell me the solution

1
2
3
4
5
6
7
8
unsigned char* hci_ll_pkt_arr;
int* hci_ll_pkt_val;   

hci_ll_pkt_arr = new(nothrow) unsigned char [param_len];
hci_ll_pkt_val = new(nothrow) int [param_len];    

hci_ll_pkt_arr = dynamic_cast<unsigned char*>(hci_ll_pkt_val); 


Errors generated after compilation
error: cannot dynamic_cast ‘hci_ll_pkt_val’ (of type ‘int*’) to type ‘unsigned char*’ (target is not pointer or reference to class)


Regards
cam
Last edited on
You must use reinterpret_cast to cast unrelated pointers.

http://www.cplusplus.com/doc/tutorial/typecasting/
since you want to convert a pointer to another type of pointer, you should use reinterpret_cast instead
Last edited on
k thanks,

Where we use dynamic_cast?
Where we use dynamic_cast?
dynamic_cast is used to cast pointers of related classes (related by inheritance).

That said, read the tutorial.

http://www.cplusplus.com/doc/tutorial/typecasting/
Topic archived. No new replies allowed.