There is a Implicit rule in Makefiles for C++ files, that use .C or .cc extension. But I usually have the .cpp file extension for C++ source.
How to use the Implicit rule for Makefile with .cpp files?
See Catalogue of Implicit Rules:
Compiling C++ programs
n.o is made automatically from n.cc, n.cpp, or n.C with a recipe of the form ‘$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c’. We encourage you to use the suffix ‘.cc’ for C++ source files instead of ‘.C’.
This is from GNU make docs.
‘%’ in a prerequisite of a pattern rule stands for the same stem that was matched by the ‘%’ in the target. In order for the pattern rule to apply, its target pattern must match the file name under consideration and all of its prerequisites (after pattern substitution) must name files that exist or can be made. These files become prerequisites of the target. Thus, a rule of the form
%.o : %.c ; recipe...specifies how to make a file n.o, with another file n.c as its prerequisite, provided that n.c exists or can be made.
So you could try something similar to
%.o : %.cpp %.hpp
$(CC) $(CFLAGS) $@
.cppshould work fine for C++..Cis usually forCcode..Cis for C++ too..cis for C..cppshould work for C++ out of the box.