0

我不明白派生文件的声明有什么问题。请帮我找到它的问题。这是我的头文件的内容:

/*
* STLSandbox.h
*
*  Created on: Aug 4, 2012
*      Author: aksinghdce
*/

#ifndef STLSANDBOX_H_
#define STLSANDBOX_H_



namespace amit {

class STLSandbox {
public:
    STLSandbox();
    virtual ~STLSandbox();
};
template<typename T>
class MyCotainer{
public:
    virtual void inserthere(T&) = 0;
    virtual void deletehere(T&) = 0;
    virtual const void printhere(T&) = 0; //promise not to modify anything
};

template<typename T>
class VectorOf: public MyContainer<T>
{
public:
    virtual void inserthere(T&);
    virtual void deletehere(T&);
    virtual const void printhere(T&);
private:
    std::vector<T&> v_data; // vector of references of type T
};

template<typename T>
void VectorOf<T>::inserthere(T& item){
    v_data.push_back(item);
}

template<typename T>
void VectorOf<T>::deletehere(T& item){
    v_data.pop_back(item);
}

template<typename T>
const void VectorOf<T>::printhere(T& item){
    std::vector<T>::iterator i = null;
            for(i=v_data.begin();i<v_data.end();i++)
            {
                std::cout<<*i<<std::endl;
            }
}

}

#endif /* STLSANDBOX_H_ */

我正在使用 gcc 4.2.1

以下是我得到的错误:

[...]/STLSandbox.h:26: error: expected template-name before ‘&lt;’ token
[...]/STLSandbox.h:26: error: expected `{' before ‘&lt;’ token
[...]/STLSandbox.h:26: error: expected unqualified-id before ‘&lt;’ token
[...]/STLSandbox.h:37: error: ‘template<class T> class amit::VectorOf’ used without template parameters
[...]/STLSandbox.h: In function ‘void amit::inserthere(T&)’:
[...]/STLSandbox.h:38: error: ‘v_data’ was not declared in this scope
[...]/STLSandbox.h: At global scope:
[...]/STLSandbox.h:42: error: ‘template<class T> class amit::VectorOf’ used without template parameters
4

1 回答 1

0

看起来它只是一个错字。您已经定义了类(注意缺少的 n),但稍后MyCotainer使用的是正确的。MyContainer

于 2012-08-05T04:13:09.760 回答