I am reading the C++ Primer (fifth edition) and I have a question. It says:
The type
void*
is a special pointer type that can hold the address of any object. Like any other pointer, avoid*
pointer holds an address, but the type of the object at that address is unknown.
Ok, so I understand that but… I have many contradictions. First of all, can't you use auto
? Doesn't it do the same thing as void
? Meaning isn't
void *somePtr;
and
auto *somePtr;
the same?
Second of all it says the type of the attached address is unknown. Can't you use typeid
to get the type? Like this:
int a = 5;
auto *somePtr = 5;
std::cout << typeid(*somePtr).name(); << std::endl;
Aucun commentaire:
Enregistrer un commentaire