【问题标题】:error C2143: syntax error : missing ',' before '<' when using template classes错误 C2143:语法错误:在使用模板类时,在 '<' 之前缺少 ','
【发布时间】:2020-03-25 13:01:18
【问题描述】:

我为我的 Stack 和 Queue 模板类继承了堆栈和队列。


template<class T>
class Stack : public stack<T> {

// 我的代码在这里 };

template<class T>
class Queue : public queue<T> {

//我的代码在这里

};

但是当我尝试在 Visual Studio 2014 上编译此代码时,我在使用的两行都收到此错误

:public stack<T>{
:public queue<T>{

如果我删除它,那么它编译没有任何错误。

我尝试在线搜索解决方案,但没有一个对我有用。

【问题讨论】:

    标签: templates inheritance


    【解决方案1】:

    所以错误是因为在使用堆栈和队列之前缺少 std::。

    类堆栈:公共 std::stack{ 类队列:公共 std::queue{

    因为我没有写“使用命名空间标准;”在我的头文件中,所以我必须在内置库中的每个新结构之前提到 std::。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-20
      • 1970-01-01
      相关资源
      最近更新 更多