Previous message assumed that you had a main function in sample.cpp. For multi-file programs, e.g., sample1.cpp and sample2.cpp, where one has main function in it, do the following
g++ -c sample1.cpp
g++ -c sample2.cpp
g++ sample1.o sample2.o -o sample
It might be a good idea to read the man page on g++. On the console type
This should open the help for g++. To move forward line by line press ENTER. To exit press Q.