【问题标题】:Class template included in another Class template C++另一个类模板 C++ 中包含的类模板
【发布时间】:2016-12-05 08:15:57
【问题描述】:

我正在尝试使用 C++ 进行编程,但遇到以下情况:

template<Class U>;
Class A<U>;
Class B;

我需要执行该代码:

A<A<B>> x;

但我得到了错误:

error: template argument 1 is invalid
warning: >> operator will be treated as two right angle brackets in C++

我也试过了:

A<(A<B>)> x;

但还是不行。我该如何管理?

【问题讨论】:

  • 请不要发布虚假代码,而是minimal reproducible example
  • 试试A&lt;A&lt;B&gt; &gt; x;
  • @Yaklefak 看来您的编译器不支持 C++11。从 C++11 开始,语法应该没问题。

标签: c++ class templates data-structures


【解决方案1】:
A<A<B>> x;

应该可以,只需添加

-std=c++14

-std=c++11

对于 g++ 标志,如果你没有,你必须在两者之间写一个空格>>

【讨论】:

    猜你喜欢
    • 2012-08-15
    • 1970-01-01
    • 2021-06-23
    • 1970-01-01
    • 2012-03-14
    • 2015-11-30
    • 2018-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多