预期一个类或命名空间;语法是正确和正确的 [英] Expected a class or namespace; syntax is proper and correct

查看:185
本文介绍了预期一个类或命名空间;语法是正确和正确的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

indualstk.h

in "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

任何想法为什么我要这个错误?最奇怪的是,这是书使用STL的C ++数据结构代码,它说,这部分应该是正确的,因为我们只是实现函数。

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.

当我去实现一个最基本的函数,我得到错误:期望一个类或命名空间。

When I go to implement a most basic function, I get the error: "Expected a class or namespace."

推荐答案

DualStack 是一个模板,因此您需要在函数实现上使用模板语法。

DualStack is a template so you need to use template syntax on your function implementation.

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

}

这篇关于预期一个类或命名空间;语法是正确和正确的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆