pool
is a global variable that happens to live in the scope of FE
; pointers to members only point to members of instances of classes.
Pointer-to-Member and static variable
-
01-09-2022 - |
Pregunta
Why I can't have pointer to member like this:
#include <iostream>
#include <stdlib.h> /* malloc, free, rand */
using namespace std;
class Pool{};
struct FE{
static Pool pool;
};
Pool FE::pool;
int main() {
Pool FE::* pmd = &FE::pool;
return 0;
}
What I am doing wrong?
Solución 2
Otros consejos
Pointer-to-members are essentially offsets into an object. That is, if you have an FE
object a pointer-to-member indicates a constant offset from the address of each FE
object. A static
object won't have a constant offset from each FE
object. Thus, the type of &FE::pool
is Pool*
and not Pool FE::*
. The two pointer types are incompatible.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow