It isn't exactly a property of a C++ program.
The actual bootcode (creating an int13h to read whatever medium your program is stored on, jumping there et cetera) has to be in the MBR (master boot record), and the entry there can't be larger than ~450 bytes (on the IA arch, anyways - 512B for the actual entry, minus the size for the partition table entry). I don't think that this can be done in C++, at least it is compiler dependent (even when writing inline asm code, you aren't guaranteed any layout of the executable, which is crucial). Write it in assembler.
Oh, and your C++ program loaded and jumped to from there has to be built with '-fno-rtti', '-f-no-exceptions' and '-f-no-builtin' (on gcc, use whatever is equivalent on your compiler - in short, you can't use anything dependent of the standard C++ runtime environment), without the STL (or did you port libc?), you don't have memory management and therefore no operator new.
Oh, and if you want to boot from grub, your code has to be multiboot compatible (this is done by writing a multiboot header, read the grub documentation).
Edit.
I once held a course on operating systems at university, we provided the code jumping into a C++ 'main()' for the students, so that they could start from there. While I may not give you the code from this project (some damn copyright issues), google for OS courses on the net. You will find many code-pieces (like a MBR entry and other startup code) readily implemented.