Curly brace expansion is one of the most useful and overlooked topic in these kind of posts. And I'm always surprised it isn't mentioned with compiling.
Worth noting that for the particular case you've cited, you can just use make, even without a makefile:
~ cat test.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "hi\n";
return 0;
}
~ stat Makefile
stat: cannot stat 'Makefile': No such file or directory
~ 1 make test
g++ test.cpp -o test
~ ./test
hi