We can’t use member selection operator (. operator) to access data members from a pointer of a struct. We need to dereference the pointer and then we can use . operator as shown below.

struct Pixel
{
    int x;
    int y;
};
 
Pixel pixel{1, 2};
Pixel *ptr{&pixel};
 
std::cout << (*ptr).x << "\n";
std::cout << (*ptr).y << "\n";

C++ provides much cleaner approach of using arrow operator that does implicit dereferencing. For example,

std::cout << ptr->x << "\n";
std::cout << ptr->y << "\n";

References

  1. https://www.learncpp.com/cpp-tutorial/member-selection-with-pointers-and-references/