c++ - 思考C++源码错误

标签 c++ templates

我正在阅读 Thinking in C++(第 2 版第 1 卷)一书,但在尝试编译此源代码时遇到问题:

http://www.linuxtopia.org/online_books/programming_books/thinking_in_c++/Chapter16_015.html

问题似乎在那一行:

堆栈::链接* p;

正如我在 C++: error "... is not derived from type ..." 中读到的那样 我必须在它前面添加单词“typename”(或“class”)。

这个例子中的书是错误的还是我遗漏了什么?

最佳答案

是的,这是错误的。您需要 typename。查看typename and template常见问题条目。

Stack 是一个依赖类型,Stack::List 也是一个依赖类型。这在 C++0x 中是合法的,但在当前的 C++ 中是非法的。

关于c++ - 思考C++源码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4419747/

相关文章:

c++ - 为什么编译器不能推导模板模板参数?

c++ - vector<double> 被转换为 vector<double, allocator<double>>

C++ XML 数据绑定(bind)

c++在while循环中获得一次输出

c++ - 使用元编程计算log2但是 `compilation terminated`

c++ - 从参数包创建不同的参数包

c++ - 模板 :Name resolution:Dependent types: -->can any one tell some more examples for this statement?

c++ - Printf 不弹出

php - 在 PHP 中使用 SwiftMailer 并通过预构建的电子邮件模板更改值

c++ - (从 istream 中提取并插入到 ostream 中)操作 : is >><T> os;