This article shortly describes how to set up the correct editor (+ correct syntax highlighting) for C++ template implementation files (extension: tpp) in Eclipse.

Syntax highlighting

Go to Window -> Preferences, then navigate to General -> Content Types. In the tree view on the right, go to Text -> C Source File -> C++ Source File -> C++ Header File and press Add… As Content Type enter *.tpp.

Do not close the preferences, yet.

File association

In Preferences, open General -> Editors -> File Associations. Press Add… and, as File Type, enter *.tpp . The editors list view at the bottom should contain the C/C++ Editor and Text Editor.


Thanks to JohnP@stackoverflow for describing this solution.

Java’s toString() method unfortunately has no standard equivalent for C++ structs and classes. If you have custom structs/classes  and want to print some debugging information of that classes to standard output, the default way is to “concatenate” the properties of interest into an output stream. Say we have a struct BeadSequence (this is taken from the beads exercise in the USACO training camp) which represents a sequence of beads which has a length and a color:

If you want some debugging information on an instance (say beadSequence) of that class, you will normally do it like this:

You need to repeat this every time you want some information on a bead sequence – terribly cumbersome! What you would want to have instead is:

BeadSequence should “know” the interesting debugging information. To this end, you may override the operator<< which is used in conjunction with std::ostream objects to output data:

The following is a minimal working example: