-1

This question has nothing to with why C++ has header files, or what extensions are commonly used for header files.

Why would a file have both ".cpp" and ".hpp" in the name?

For example,

example.cpp.hpp

Sorry if the answer seems obvious or easily searched, but I've looked through a number of different search engines and can't find anything.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
Lightyear Buzz
  • 796
  • 7
  • 28
  • I don't believe you bothered to read my question. Nothing on that page has filename that ends in ".cpp.hpp" – Lightyear Buzz Jul 25 '16 at 01:40
  • 1
    It's possible this is a file for template definitions, which need to be in the same TU. I've never seen anyone use that as an extension, so it's the only thing I can think of apart from something adding the .cpp extension automatically. – chris Jul 25 '16 at 01:40
  • 1
    Maybe someone did not understand that `.hpp` means "C++ header", so he wanted to point out with the .cpp that the file is written in C++ – user4759923 Jul 25 '16 at 01:46
  • @user4759923 I'm a little hesitant to believe that since there are plenty of other files that he wrote with a .hpp extension and the fact that this guy is on the level of a principal engineer and has been writing C++ professionally for more than a few decades. – Lightyear Buzz Jul 25 '16 at 01:50
  • @LightyearBuzz Well, it's simply silly dong such, or asking about. Kick the _principal engineer_ in their ass, since they did something obviously wrong. – πάντα ῥεῖ Jul 25 '16 at 01:51
  • Maybe it was a source file some times ago, and then it was converted to a header – user4759923 Jul 25 '16 at 01:52
  • Perhaps you should try ask the person that created the file. – Disillusioned Jul 25 '16 at 01:53
  • IMO, certainly a mistake, probably caused by misuse of an IDE. E.g., have the IDE open a wizard for a "new class" or something and enter a filename, including `.cpp`, not noticing that the IDE template that opened is for a header file. Or vice versa. – davidbak Jul 25 '16 at 02:18

1 Answers1

1

Your file is a almost certainly a header file, because of the .hpp extension. (It could be a source file, no one knows, the extension doesn't mean anything).

Note that only .hpp is the extension, not .cpp.hpp. The actual file name is example.cpp. There can only be one extension for any given file.

Why would anyone do that? Here's a theory:

The default option on Windows (I think) is to hide file extensions. The person maybe tried to change the extension, by renaming the file. But because the actual extension was hidden, he added .cpp to the actual filename, and so the file became example.cpp.hpp. Because the .hpp part was hidden, the person thought that the file had the correct extension, when it hadn't.

Rakete1111
  • 47,013
  • 16
  • 123
  • 162
  • By convention, a header would have a .hpp extension (.cpp could be a header if you wanted it to be). However, .cpp.hpp isn't exactly a widely-used convention in the first place. – chris Jul 25 '16 at 01:54
  • @chris Really? I though that was the convention.. Is it `.cc`? – Rakete1111 Jul 25 '16 at 02:01
  • One file having the full .cpp.hpp is not a convention I have seen. .cc, .cpp, and .hpp all are. – chris Jul 25 '16 at 02:16
  • @chris I know, I haven't said that either. Can you please tell me the line where I said that so that I can change it because I can't find it. Thanks. (Or maybe do you mean my comment, I was referring to `.cpp`, sorry) – Rakete1111 Jul 25 '16 at 02:45
  • Just the definitive "Your file is a header file, because of the .hpp extension.", since the main requirement is simply being a text file regardless of extension. – chris Jul 25 '16 at 03:16
  • @chris Oh, I see. Thanks :) – Rakete1111 Jul 25 '16 at 03:20