Expression must have class type

It’s a pointer, so instead try:


Basically the operator . (used to access an object’s fields and methods) is used on objects and references, so:

A a;
A& ref = a;

If you have a pointer type, you have to dereference it first to obtain a reference:

A* ptr = new A();

The a->b notation is usually just a shorthand for (*a).b.

A note on smart pointers

The operator-> can be overloaded, which is notably used by smart pointers. When you’re using smart pointers, then you also use -> to refer to the pointed object:

auto ptr = make_unique<A>();

Leave a Comment