I have been working my way through Dirk Eddelbuettel\'s Rcpp
tutorial here:
http://www.rinfinance.com/agenda/
I have learned how to save a C++ file
If you want to get some entity you can keep, what you are looking for is an R
package. There are many resources online to learn how to make them (e.g. Hadley's slides).
We have Rcpp.package.skeleton
you might find useful.
So, the function is compiled once when the package is installed, and then you just use it.