没有扩展名的C ++头文件

编程入门 行业动态 更新时间:2024-10-23 03:28:03
本文介绍了没有扩展名的C ++头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用一个开源项目(Open Scene Graph).我发现所有标头文件名均采用 File 格式,正如某些网站中提到的那样,我发现它是无扩展名的文件.

I am using an open source project (Open Scene Graph). I found that all the header file names are in File format, which I found to be File With No Extension as mentioned in some website.

我想知道为什么那些开发人员使用此扩展名,而不是传统的 .h 文件扩展名.

I would like to know why those developer used this extension, rather than the traditional .h file extension.

推荐答案

似乎您在谈论此存储库 C ++代码.

It seems you are talking about this repository of C++ code.

该代码的作者似乎决定遵循C ++标准库的模式.在标准C ++中,库标头不应具有 .h 扩展名.所以以下是正确的:

It looks like the authors of that code decided to follow the patterns of the C++ standard library. In standard C++, library headers are not supposed to have the .h extension. So the following is correct:

#include <iostream>

对于大多数实现,编写< iostream.h> 也是可以的,但是没有扩展名的版本实际上是正确的.由于引入了命名空间,并且引入了标准库的 std 命名空间,因此C ++标准库能够删除C ++ 98中的扩展.

With most implementations writing <iostream.h> would also work, but the version without an extension is actually correct. The C++ standard library was able to drop extensions in C++98 due to the introduction of namespaces, and introduction of the std namespace for the standard library.

C ++标准既不需要也不禁止扩展其他标头,因此,完全由某些软件的作者决定使用什么文件扩展名(如果有).最常见的选择是使用 .h 或 .hpp ,后者旨在区分C ++头文件和C头文件.

The C++ standard neither requires nor forbids an extension for other headers, so it's entirely up to the authors of some software what file extension to use, if any. The most common choices are to use .h or .hpp, the latter being intended to distinguish C++ headers from C headers.

快速浏览OpenSceneGraph代码表明它们遵循了包含中的C ++标准库模式.没有扩展,一切都在 osg 命名空间中,类似于标准库的 std 命名空间.因此,使用OpenSceneGraph库与使用C ++标准库非常相似.

A quick look at the OpenSceneGraph code shows that they've followed the C++ standard library pattern in their includes. There are no extensions, and everything is in the osg namespace, analogous to the std namespace of the standard library. So using the OpenSceneGraph libraries is very similar to using the C++ standard library.

#include <osg/Camera> // Provides osg::Camera

与以下模式相同:

#include <string> //Provides std::string

因此,我认为可以肯定地说OSG的作者希望遵循与C ++标准库中相同的模式.我个人认为,最好具有文件扩展名,即使只是能够搜索头文件也是如此.

So I think it's safe to say that authors of the OSG wanted to follow the same pattern as in the C++ Standard Library. My personal opinion is that it's better to have a file extension, even if only to be able to search for header files.

更多推荐

没有扩展名的C ++头文件

本文发布于:2023-11-17 07:23:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609288.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:扩展名   头文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!