The title is not very specific but what I am referring to is stuff like having a function accept a pointer to another function. See below for what I am referring to, like why does this mean accept a pointer to a void function with a void * arg? And where is this documented? (And other random information like this)
Also I typed this example code in the browser so there is probably a few errors.
#include <iostream>
void Work(void * args)
{
//Assume args is char*
std::cout << (char*)args << std::endl;
}
//Callable is what I am referring to, why does this represent a function? And what documentation specifies it?
void DoWork(void (*callable)(void*), void* args)
{
callable(args);
}
int main()
{
DoWork(Work, (void*)"Some info");
}
The official source where all this is documented is the C++ standard. It's unfortunately not freely available, but in practice that doesn't matter because it's easy to find publicly available drafts that is as good as identical. The standard isn't meant to be learning material but rather for compiler and standard library implementers. For more digestive information you'll have to look elsewhere. E.g. books, courses, websites, blog posts, etc. The page that keskiverto linked to (cppreference.com) is great for looking things up, but it's rather technical so I'm guessing it can be confusing to beginners (even I get confused sometimes).
This is free and what I used. not this very link but solo-learn has a full free course, u can get the app on your phone and go to the module, arrays and pointers.
//Callable is what I am referring to, why does this represent a function? And what documentation specifies it?
void DoWork(void (*callable)(void*), void* args)
if it helps, the name of the function IS a pointer, in the same sense that the name of an array IS a pointer. (technically, I guess they are const pointers since you can't (or should not!!) mess with them). You see that in your example, but its easy to miss. This helps because most uses of function pointers don't use * syntax, they just use the names... I know they are useful in C++, but I havent had the need.
the name of an array IS a pointer. (technically, I guess they are const pointers
Technically they are nothing at all like pointers, const or otherwise. It's like saying "the name of a double IS an int (technically a const int)". An implicit conversion is not an "IS a" relationship.
Fair enough. But the result of the unseen conversion (for function*) is a, and its very handy to let the compiler do this for you when dealing with them.