【问题标题】:using `extern` with typedef-name使用带有 typedef-name 的 `extern`
【发布时间】:2017-04-09 00:23:26
【问题描述】:

如果我们有

typedef std::vector<int> INT_VEC

如果我在这样的任何源文件中使用INT_VEC -

extern template class INT_VEC

我得到错误 - 在class 之后使用 typedef-name INT_VEC

即使using(又名通过alias)也无法解决它。怎么可能解决。

【问题讨论】:

  • 我认为除了 EDG 前端之外的任何编译器都不支持外部模板。
  • 我试过 gcc 和 msvc 都支持 extern 但不支持 typedefs。
  • 哦,我的错,我在考虑export template。别介意我的评论。
  • @rubenvb 你有什么想法吗,如何externtypedef
  • 你不能告诉编译器“我的类型是在这个或另一个翻译单元的其他地方定义的”,就像你对变量(静态/全局)所做的那样。请记住,此上下文中的 extern 仅适用于变量 - 它不能应用于类型。您是否尝试过 - extern Int32.. 其中Int32 是某种 int 类型的 typedef?

标签: c++11 templates c++14 alias


【解决方案1】:

这样的?

extern INT_VEC your_external_variable;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-25
    • 2011-09-17
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多