For a temporary session (or in a possibly local .vimrc file), you can specify the builtin makeprg variable (see also :help makeprg)
set makeprg=g++\ -o\ myprogram\ file1.cpp\ file2.cpp
and invoke the compilation via :make. This will open up the quickfix window if you had any compilation errors or warnings, which can be handy.
Note, however, that this is nothing but a temporary hack for quick trial-and-error cycles. When these two files are meant to be something more serious, choose a build system and configure it accordingly. Then, adjust the makeprg variable again to invoke e.g. make (which is the default anyway), ninja, scons (in case you hate yourself) or whatever tool you chose.
g++invocation for this.