If you're using SDL then the answer is "you can get kind of close to your desire, up to the last step, sort of". Being able to write a game-like program in a single codebase, and then take that codebase to various machines and compile it and have it work is exactly what the Simple DirectMedia Library was designed to do! It wouldn't be very popular if it didn't at least make this a reasonable target.
That won't mean you'll be able to push a button and get a Macintosh or Linux binary package out of Visual Studio. But you could always find friends and ask them to try the compilation for you on the codebase. So long as you've been careful to only call functions out of the standard C++ library AND stay inside the box that SDL gives you, it should compile fine...in theory.
Update 2018: - If you want to compile on Mac and don't have one, Travis-CI now has virtualized OS X, so you can run clang and actually have it upload the resulting binaries somewhere. You probably don't want to wait for a full build over the network each time you make a change...but once you get a cross-platform codebase building on OS X, continuous integration can make sure you keep it that way.
It can be harder in C++ than it is in other languages to make sure you're staying within a "portability sandbox" (especially if you're a beginner). And it can be harder if you're following tutorials targeting Microsoft tools especially, as they have few qualms about advising you to make Windows-only calls in their documentation. So the odds of being able to hand the "fully debugged" code to a friend, have it compile and work on a new platform the first time will be low.
You'll need a testing period, certainly. And you probably shouldn't wait until the last minute to have someone else make sure the basics are working by compiling it in XCode or whatever. You can lower the risk of writing nonportable code by using the GCC compiler instead, which will be more likely to complain if you start bringing in dependencies that are not actually cross platform.
It also may be possible to run a "Hackintosh" virtual machine if you like living on the edge. You can certainly make a Linux VM and try building under that, and if it works that will raise the confidence that a Mac build will work too. Won't guarantee it though.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…