Fix C++ "request for member in pointer type" — Use -> on Pointers, and Why -> Cannot Fix a Non-Class Type
One dot in the wrong place, two different errors. This guide separates them: the pointer that only needed an arrow, the dereference form that needs its parentheses, the non-class error where no operator change helps because the value has no members at all, and the smart-pointer case where dot and arrow are both correct and mean different things.
Written November 22, 2026 · Tested with GCC 13.3.0 · 16 min read
- The first failure: a dot on a pointer
- Reading the error: pointer type versus non-class type
- The fix: the arrow, and the dereference it abbreviates
- The second failure family: a member request on a non-class type
Written November 22, 2026
Tested with GCC 13.3.0
What this guide is
Member access in C++ comes in two built-in forms, and each states what its left-hand side must be. The dot form, E1.E2, requires E1 to be an expression of complete class type: an object, or a reference to one. The arrow form, E1->E2, requires E1 to be an expression of pointer to complete class type. For built-in types one equivalence ties them together: E1->E2 is exactly equivalent to (*E1).E2. The arrow is not a separate lookup mechanism; it is the dereference and the dot written as one operator.
The title error is what happens when the first form is given the second form's operand. A pointer is not the object it points to. Writing p.value where p is a pointer asks for a member of the pointer itself, and a built-in pointer has no members, so the compiler reports the request as made in a value of pointer type and, when the pointed-to type is a class type, suggests the arrow. The repair is one character pair: change the dot to an arrow, or dereference explicitly with parentheses.
The sibling error in the second half of this guide shares the first half of its wording and none of its repair. request for member 'size' in 'n', which is of non-class type 'int' also reports a member request that cannot be satisfied, but there is no pointer confusion to undo: an int has no members, and switching the dot to an arrow fails one dereference later at best. That error is a design signal — the wrong variable, the wrong type, or a member that was never written — fixed by changing what the code asks for, not by changing the operator.
This guide works through the failures in the order that separates the causes: the dot on a pointer and its suggestion, the arrow fix and the parenthesized dereference, the trap where the dereference without parentheses fails identically on precedence, the non-class family on an int and a pointer to int, and finally std::unique_ptr, where the dot reaches the smart pointer's own members and the arrow reaches the managed object's members, so both spellings compile and choosing between them is choosing an object, not fixing a typo.
Build every program in this guide with g++ -std=c++17. Nothing here needs a newer standard.
The first failure: a dot on a pointer
The smallest version of the problem is a struct, a pointer to it, and one member access written with a dot:
#include <iostream>
struct Reading {
int value;
};
int main() {
Reading r{42};
Reading* p = &r;
std::cout << p.value << '\n';
return 0;
}
$ g++ -std=c++17 -g -Wall -Wextra -o fail_dot_on_pointer fail_dot_on_pointer.cpp
fail_dot_on_pointer.cpp: In function 'int main()':
fail_dot_on_pointer.cpp:10:20: error: request for member 'value' in 'p', which is of pointer type 'Reading*' (maybe you meant to use '->' ?)
10 | std::cout << p.value << '\n';
| ^~~~~
Read the error in its three parts. The first names the member requested, value, and the expression it was requested in, p. The second gives the type that made the request impossible: p is of pointer type Reading*, and the dot operator's operand must be an object of class type, not a pointer to one. The third, in parentheses, is GCC's repair suggestion: maybe you meant to use ->. It appears because the pointed-to type, Reading, is a class type: a pointer to a class type is exactly the operand the arrow is for, so GCC names it. The suggestion is keyed to the pointee being a class type, not to the member existing — GCC prints it even for a member name the class does not have, and following it then surfaces a has no member named error for the name itself. In this program the member does exist, so here the suggestion is the complete diagnosis: the right object is one dereference away, and only the access operator is wrong.
Note what the error is not. It is not a complaint that value does not exist — it is declared in the struct above the failing use. It is not a complaint about the value stored in the pointer, which is never examined at compile time; the same error appears if p is null or uninitialized, because the failure is in the type of the expression. The single mismatch is between the operator, which wants an object, and its operand, which is a pointer.
Reading the error: pointer type versus non-class type
GCC uses one sentence frame for this whole family — request for member '<name>' in '<expression>', which is of ... — and the ending is the part that decides the fix, so read the ending first.
The ending of pointer type '<T>*', followed by the maybe you meant to use '->' ? suggestion, means the operand is a pointer to a class type. The repair is mechanical when the named member exists on that class: use the arrow, or dereference and use the dot. If the name itself is wrong, the arrow only advances the error to has no member named — the suggestion guarantees the operator family, not the member. Nothing about the program's design is in question.
The ending of non-class type '<T>', with no suggestion, means the operand's type is not a class type at all. There is no member list to search, on the operand or on the pointee either. No operator change repairs this form, because both built-in operators require a class type somewhere: the dot requires it of its operand, the arrow of the pointee. When neither side supplies one, the member request itself is wrong.
A third ending appears with class-type operands that lack the named member, shown live in the std::unique_ptr section below: the wording changes to has no member named '<name>'. That form means the operator was right and the member name, or the object the access was aimed at, was wrong. Three endings, three different repairs — which is why this family rewards reading the whole line instead of reaching for the arrow every time.
The fix: the arrow, and the dereference it abbreviates
Change the dot to an arrow and the program compiles. The same program also shows the expanded form the arrow abbreviates, and the reference form, where the dot is the correct operator:
#include <iostream>
struct Reading {
int value;
};
int main() {
Reading r{42};
Reading* p = &r;
Reading& ref = r;
std::cout << p->value << '\n';
std::cout << (*p).value << '\n';
std::cout << ref.value << '\n';
return 0;
}
$ g++ -std=c++17 -g -Wall -Wextra -o fixed_arrow fixed_arrow.cpp
$ ./fixed_arrow
42
42
42
Three lines, three routes to the same member of the same object, and the output confirms they agree. p->value is the arrow form: its operand is the pointer, and the member is looked up in the pointed-to type. (*p).value is the same access written out: indirection applied to a pointer yields the object it points to — formally, an lvalue referring to that object — and the dot then applies to that object, which is exactly the equivalence the arrow is defined by. ref.value is the plain object form through a reference: a reference is another name for the object itself, not a pointer, so it takes the dot, and ref->value would be the mirror-image error.
In ordinary code, write the arrow for pointer access. It states the operand's kind at the access site and chains without accumulating parentheses. Keep the expanded form in mind rather than in the code: knowing the arrow is a dereference plus a dot is what lets you read the non-class errors below, where GCC performs that expansion in its own diagnostic and reports the error against * p instead of the pointer you wrote.
One caution: neither form checks the pointer. Dereferencing a null pointer, or one that does not point to a live object, is undefined behavior in either spelling. Fix the operator to fix the diagnostic; check the pointer's validity, where it can be in doubt, as a separate step.
The trap: the dereference without parentheses
#include <iostream>
struct Reading {
int value;
};
int main() {
Reading r{42};
Reading* p = &r;
std::cout << *p.value << '\n';
return 0;
}
$ g++ -std=c++17 -g -Wall -Wextra -o fail_star_no_parens fail_star_no_parens.cpp
fail_star_no_parens.cpp: In function 'int main()':
fail_star_no_parens.cpp:10:21: error: request for member 'value' in 'p', which is of pointer type 'Reading*' (maybe you meant to use '->' ?)
10 | std::cout << *p.value << '\n';
| ^~~~~
The error is identical to the first failure's, down to the suggestion. That identity is the lesson: the compiler never applied the star to p at all. Member access binds more tightly than indirection — a.b and a->b sit in the postfix group of the precedence table, one level above the unary operators, where prefix *a indirection sits — so *p.value is parsed as *(p.value). The inner expression is the original dot-on-pointer expression, and it earns the original error before the outer dereference is ever considered. Precedence decides the grouping, and here it groups the dot with the pointer before the star can reach it.
The parentheses in (*p).value are therefore not decoration. They override the default grouping, forcing the indirection first so the dot receives the object it requires. Remove them and the expression becomes a different expression, one whose inner part is ill-formed. Whenever a dereference combines with member access, a subscript, or a function call in one expression, the postfix operators group first — so write the parentheses, or use the arrow, which makes this grouping mistake impossible.
The second failure family: a member request on a non-class type
Change the operand from a pointer to a struct into a plain int, and ask it for a member that container types made familiar:
#include <iostream>
int main() {
int n = 42;
std::cout << n.size() << '\n';
return 0;
}
$ g++ -std=c++17 -g -Wall -Wextra -o fail_nonclass_int fail_nonclass_int.cpp
fail_nonclass_int.cpp: In function 'int main()':
fail_nonclass_int.cpp:5:20: error: request for member 'size' in 'n', which is of non-class type 'int'
5 | std::cout << n.size() << '\n';
| ^~~~
No suggestion follows this error, and the absence is diagnostic. GCC suggests the arrow when there is a class type on the other side of a dereference — the pointee being a class type is what puts the arrow in play, whether or not the named member exists on it. An int is not a class type, it has no members, and there is no dereference to insert, because n is already the value itself. The request is not misspelled; it is addressed to a type that cannot answer it.
The same shape of mistake through a pointer produces a wording worth seeing exactly, because it differs from the title error in a way that is easy to misread:
#include <iostream>
int main() {
int n = 42;
int* p = &n;
std::cout << p.size() << '\n';
return 0;
}
$ g++ -std=c++17 -g -Wall -Wextra -o fail_ptr_to_int_member fail_ptr_to_int_member.cpp
fail_ptr_to_int_member.cpp: In function 'int main()':
fail_ptr_to_int_member.cpp:6:20: error: request for member 'size' in 'p', which is of non-class type 'int*'
6 | std::cout << p.size() << '\n';
| ^~~~
Here the operand is a pointer, yet the ending says non-class type, naming the pointer type itself, int*, and again no arrow suggestion. No suggestion appears here because the pointee is not a class type at all: the suggestion tracks the pointee's kind, and an int pointee gives the arrow nothing to work on — p->size() would only move the request one dereference closer to the same dead end. Compare the first failure, where the pointee was a struct and the suggestion appeared. The presence or absence of that suggestion is GCC telling you whether the pointee is a class type, not whether the named member exists on it: a misspelled member on a class pointee still earns the suggestion, and the arrow then fails one step later with has no member named. Present: change the operator first, then let the member lookup judge the name. Absent, on a pointer operand: the problem is the member request, not the operator.
The real fix depends on what the code meant, and the error cannot tell you. If size was wanted, the value that has one is some container — a string, a vector — and the access belongs on that variable, not on a count or an element. If the member was wanted on a class of your own, the variable in hand is the wrong one, or the member was never added. In every branch the edit is to the variable, the type, or the class definition. The operator is the one thing that stays.
Why the arrow does not fix the non-class error
It is worth applying the suggested-looking repair once, in a program of its own, to see exactly how it fails:
#include <iostream>
int main() {
int n = 42;
int* p = &n;
std::cout << p->size() << '\n';
return 0;
}
$ g++ -std=c++17 -g -Wall -Wextra -o fail_arrow_on_int fail_arrow_on_int.cpp
fail_arrow_on_int.cpp: In function 'int main()':
fail_arrow_on_int.cpp:6:21: error: request for member 'size' in '* p', which is of non-class type 'int'
6 | std::cout << p->size() << '\n';
| ^~~~
The error moved, and its movement proves the equivalence from the first section. GCC reports the request as made in * p — the dereferenced pointer, with the space its diagnostic inserts — because the arrow is (*p).size() by definition, so the member lookup ran against the type of the pointee, int, a non-class type, and failed there instead. The arrow did precisely its job; the job was not the one the code needed, because no request for a named member on an int, through any operator, can succeed.
Run this test mentally before editing any error in this family. Expand the arrow by hand: write the type of the pointee in place of the pointer, and ask whether that type has the member. Reading has value, so the arrow repairs the first failure. int has no members at all, so the arrow only relocates this one. A member request needs a class type at the end of the access, and when neither position holds one, stop editing operators and find the value that does.
References take the dot; std::unique_ptr takes both, for different objects
Two cases remain where the choice between dot and arrow is not an error at all.
The reference case was already in the fix program: ref.value, with a dot, where ref is a Reading&. A reference designates the object itself — indirection through a pointer yields an lvalue referring to the pointed-to object, and binding that lvalue is the ordinary way references are formed — so the reference and the object are accessed identically. Dot for objects and references of plain class types, arrow for pointers: the operator follows the declared kind of the variable, not how the object was originally reached. One class of types breaks that split deliberately — a class that overloads operator->, covered next, takes the arrow on the object or reference itself for the pointed-to object's members.
std::unique_ptr breaks the one-variable-one-operator pattern, deliberately. A unique_ptr is itself a class object — a smart pointer that owns and manages another object through a pointer and disposes of it when the unique_ptr goes out of scope — and it provides an overloaded operator-> returning a pointer to the managed object, alongside ordinary members of its own such as get, which returns a pointer to the managed object, and reset, which replaces the managed object. Its operator* returns the managed object itself, equivalent to dereferencing the pointer returned by get(). On one variable, the arrow is redirected by the overload to the managed object, while the dot stays with the unique_ptr itself:
#include <iostream>
#include <memory>
struct Reading {
int value;
};
int main() {
auto up = std::make_unique<Reading>(Reading{42});
std::cout << up->value << '\n';
std::cout << (*up).value << '\n';
std::cout << (up.get() != nullptr) << '\n';
up.reset(new Reading{7});
std::cout << up->value << '\n';
return 0;
}
$ g++ -std=c++17 -g -Wall -Wextra -o fixed_unique fixed_unique.cpp
$ ./fixed_unique
42
42
1
7
Read the four output lines as two pairs. up->value and (*up).value both print 42, for the same reason the raw-pointer forms agreed: the overloaded arrow returns the stored pointer and built-in member access runs on the pointee, while the overloaded star returns that same pointee for the dot. Then up.get() and up.reset(...) use the dot to reach members of the unique_ptr itself — the manager, not the managed object — and after the reset, up->value prints 7. Both spellings compile throughout, and each is correct, because they address different objects reachable from one variable.
The failure mode in this case is aiming the dot at the managed object's member. value is a member of Reading, not of unique_ptr, so the dot form earns the third wording from the reading-the-error section:
#include <iostream>
#include <memory>
struct Reading {
int value;
};
int main() {
auto up = std::make_unique<Reading>(Reading{42});
std::cout << up.value << '\n';
return 0;
}
$ g++ -std=c++17 -g -Wall -Wextra -o fail_unique_dot fail_unique_dot.cpp
fail_unique_dot.cpp: In function 'int main()':
fail_unique_dot.cpp:10:21: error: 'class std::unique_ptr<Reading, std::default_delete<Reading> >' has no member named 'value'
10 | std::cout << up.value << '\n';
| ^~~~~
That error is good news about the operator and bad news about the target: the dot was applied to a class type, as it requires, and that class has no member with that name — because the member lives on the managed object, one arrow away. The general rule, for smart pointers and every other case in this guide, is to name the object whose member you want before choosing the operator. The variable's own object takes the dot; the object it points to or manages takes the arrow.
The fixes, ranked
On a pointer to a class type, change the dot to the arrow. p->value for p.value, when the error ends in of pointer type and carries the maybe you meant to use '->' ? suggestion. This is the complete fix for the title error: the member and the object both exist, and only the operator mismatched the operand.
Write the dereference explicitly only with its parentheses. (*p).value is exactly equivalent to the arrow for built-in pointers and is the right form when the dereferenced object itself is what the surrounding expression needs. Without the parentheses, precedence regroups the expression to *(p.value) and reproduces the original error unchanged.
Use the dot for objects and for references of plain class types. A reference designates the object, so ref.value is correct and, for a plain class type such as Reading, ref->value is the mirror-image mistake. The carve-out is a class type that overloads operator-> — a smart pointer, an iterator: its objects and references take the arrow too, for the pointed-to object's members, as the next bullet covers. When a variable is converted between object, reference, and pointer, every access site changes operator with it — a missed site is the most common way this error enters existing code.
On a smart pointer, choose the operator by naming the target object first. The arrow, through the overloaded operator->, reaches the managed object's members; the dot reaches the smart pointer's own members, such as get and reset on std::unique_ptr. Both compile, so read these accesses by target, not by habit.
On a non-class type error, do not change the operator at all. No request for a named member succeeds on a non-class type, as operand or as pointee. Find the variable of class type that has the member — a container for size, the class instance for a user-defined member — or add the member, or change the type.
Which fix for which error
request for member '<m>' in '<p>', which is of pointer type '<T>*' (maybe you meant to use '->' ?): the operand is a pointer to a class type. Change the dot to an arrow, or write(*p).<m>with the parentheses; if the member name itself is wrong, the arrow surfaces that next ashas no member named.- The identical pointer-type error from an expression written with a leading star, such as
*p.<m>: precedence grouped the dot first. Add the parentheses to make(*p).<m>, or switch to the arrow. request for member '<m>' in '<n>', which is of non-class type '<T>'on a plain value: the type has no members. The access belongs on a different variable, or the type or class definition has to change; no operator edit helps.request for member '<m>' in '<p>', which is of non-class type '<T>*'on a pointer: the pointee is a non-class type with no members, which is why no arrow was suggested. Aim the access at a class-type value instead; the arrow would only move the error to the pointee.request for member '<m>' in '* p', which is of non-class type '<T>': an arrow was already applied and the pointee has no such member because it has no members at all. Undo the member request, not the arrow.'class <C>' has no member named '<m>': the operator matched the operand — a class object accessed with a dot — but that class has no such member. Check for a misspelled member, and for a smart pointer whose intended member lives on the managed object and needs the arrow.
Checklist
- Read the ending of the error before editing:
of pointer typewith the suggestion means the pointee is a class type and the operator is the first thing to change, with the member name judged after;of non-class typemeans change the variable, type, or class;has no member namedmeans the operator was fine and the member or target was wrong. - Confirm the operand's declared kind at the access site: object or reference of a plain class type takes the dot, pointer takes the arrow, a type with an overloaded
operator->takes the arrow on the object or reference too, and a change in how a variable is declared means every one of its access sites changes with it. - Expand any arrow by hand when the fix is in doubt: the member must exist on the type of the pointee, or the arrow only relocates the error.
- Keep the parentheses in every explicit dereference combined with member access —
(*p).member— and prefer the arrow where the parentheses would only repeat it. - On a
std::unique_ptror another class with an overloaded arrow, name the target before writing the access: dot for the manager's own members such asgetandreset, arrow for the managed object's members. - Treat a member request on an
intor another non-class type as a design signal, not a typo: locate the container or class object the member actually belongs to.
Related guides on this site
- C++ Pointers and References — the underlying model this error tests: what a pointer holds, what dereferencing yields, and how a reference differs from both.
- C++ Classes and Objects — where members come from: declaring data members and member functions, and accessing them on an object.
- Fix C++ "no match for 'operator<<'" — the error that often surfaces next in the same statement, once the member access compiles and the stream insertion itself has no matching overload.
- Fix C++ "'cout' was not declared in this scope" — the sibling first-line error in the same minimal programs: a name-lookup failure on the stream object, separated into its missing-header and missing-qualification causes.
Sources
- cppreference, Member access operators — for the dot form requiring an expression of complete class type, the arrow form requiring a pointer to complete class type, the equivalence of
E1->E2and(*E1).E2for built-in types, and the recursive application of a user-definedoperator->until a plain pointer is reached. - cppreference, Pointer declaration — for pointers appearing as operands of the built-in indirection operator, which returns the lvalue expression identifying the pointed-to object, and for pointers to class objects appearing as the left-hand operands of the member access operators.
- cppreference, C++ Operator Precedence — for member access
a.banda->bsitting in the postfix group above unary indirection*a, so that an operator listed higher binds tighter than one listed lower and*p.valuegroups as*(p.value). - cppreference, std::unique_ptr — for
std::unique_ptrowning and managing another object via a pointer and disposing of it when theunique_ptrgoes out of scope, and forgetreturning a pointer to the managed object andresetreplacing it. - cppreference, std::unique_ptr operator* and operator-> — for
operator->returning a pointer to the object owned by theunique_ptr, foroperator*returning that object, equivalent to dereferencingget(), and for both being provided only for the single-object version ofunique_ptr.
Keep Exploring
Seven tips and seven puzzles so far, each one a short runnable example with the fix explained.
Paste an AddressSanitizer, UBSan, or ThreadSanitizer report and get the bug, the file and line, and the fix \u2014 in plain language.
C++20 and C++23 features, migration paths, and measured trade-offs.
The full C++ hub \u2014 language basics, the standard library, coroutines, and measured comparisons.
Paste a [Service] section and get a plain-language verdict on every sandboxing setting it finds.