Is there anyway to do something like this?
(correct pointer datatype) returnPointer(void* ptr, int depth)
{
if(depth == 8)
return (uint8*)ptr;
No; you can't do that in C++. The correct answer is to return void *.
Think about it from the opposite side of the call -- and from the compiler point of view at that:
How would the compiler be able to verify if the return value is used correctly (like assigned to a variable of the proper type, for example), if it cannot possibly know which of the three return types will be returned?
At that point, the notion of assigning "one of multiple types" to the return value becomes meaningless. The return type of a function has no other purpose in life than to make it possible for the compiler to do it's job; the compiler needs "one" type to be able to do type checking. Since you don't know which one it is until runtime, the compiler can't do the type checking for you. You have to tell the compiler to "stop trying" to match the return value to any specific pointer type -- hence, return a void *.
If your depth arguments is known at compile time, you can alternatively use a set of templates like @sth demonstrated, or use a set of separate independent functions, or use a set of related functions that call a shared implementation function and then cast the return to the proper type. Which one you chose is a mostly an aesthetic decision.
If the value of depth is not know until run-time, then you should probably return void *.
Now, I'm assuming that your actual implementation actually does something to produce the pointer other than what your sample code shows. Your sample code is not an actual function; it's more like trying to duplicate what a cast does. A cast is not a function call; it's a compiler directive to try to "make" it's operand into a specific type (exactly 'how', is a long story for another post). It's not a C++ language operation, but a compiler operation. You can't rewrite that in C++ itself.