No, that doesn’t work; shortcodes are for content files (but there is nothing you cannot do in a template file that a shortcode file can).
What you can do, if all you want is a HTML file and do not need markdown content etc., you can do put the html directly into /content, so /content/test.html:
<html>
<h1>Test</h1>
{{< foo >}}
</html>
Will work and accessible at http://localhost:1313/test/ or http://localhost:1313/test.html if uglyUrls.
This is a somewhat hidden feature in Hugo.
As to reading the “example.cpp”, see https://github.com/spf13/hugo/pull/2008
I will probably wrap that up later today.