简体   繁体   English

期望一个类或命名空间; 语法是正确和正确的

[英]Expected a class or namespace; syntax is proper and correct

in "dualstk.h" 在“dualstk.h”中

#ifndef __32_dualstk_h
#define __32_dualstk_h

#include <deque>
#include <cstdlib>
#include <iostream>

using namespace std;

enum stackNumber {One, Two};

template <class T>

class DualStack{
public:
    DualStack() {count1 = 0; count2 = 0;};
        //constructor. set counts to 0

    void push(const T& item, stackNumber n);
    void pop(stackNumber n);

    T& top(stackNumber n);
    const T& top(stackNumber n) const;

    bool empty(stackNumber n) const;
    int size(stackNumber n) const;

private:
    deque<T> dualstackElements;
    int count1, count2;

};

//error here
void DualStack::pop(stackNumber n){

}

#endif

Any idea why I'm pulling this error? 知道我为什么要拉这个错误吗? What's strangest is that this is the book "Data Structures with C++ using STL" code and it states that this part is supposed to be correct as we are to simply implement the functions. 最奇怪的是,这是“使用STL的C ++数据结构”一书的代码,并指出这部分应该是正确的,因为我们只是简单地实现这些功能。

When I go to implement a most basic function, I get the error: "Expected a class or namespace." 当我去实现一个最基本的函数时,我得到错误:“期望一个类或命名空间。”

DualStack is a template so you need to use template syntax on your function implementation. DualStack是一个模板,因此您需要在函数实现上使用模板语法。

template <class T>
void DualStack<T>::pop(stackNumber n){

}

create a separate file for your function implementation and include your header file 为您的函数实现创建一个单独的文件,并包含您的头文件

#include "dualstk.h"

void DualStack::pop(stackNumber n){

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM