gpt4 book ai didi

c++ - 头文件中类型名称的显式限定

转载 作者:行者123 更新时间:2023-11-28 04:07:59 24 4
gpt4 key购买 nike

The C++ Programming Language 第 4 版的第 432 页介绍了桌面计算器的界面。 string 和 istream 之类的名称似乎是“裸露的”(没有 std 资格)。我可以在自己的声明中模拟这种行为吗,如下所示:

标题.h

// This is header.h

#include <string>
#include <vector>

extern string s;
void func(vector<int> vi);

// and so on

...或者字符串和 vector 之类的名称是否需要明确限定?

最佳答案

书的第 89 页指出

For simplicity, I will rarely use the std:: prefix explicitly in examples. Neither will I always #include the necessary headers explicitly. To compile and run the program fragments here, you must #include the appropriate headers (as listed in §4.4.5, §4.5.5, and §30.2) and make the names they declare accessible.

关于c++ - 头文件中类型名称的显式限定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58357251/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com