我对继承STL向量的类的定义有一些疑问。此类是公开继承自std :: vector的前提,但是我一直从compiter中收到以下错误。我几乎可以肯定,这是由于<vector>
的错误造成的,但我不知道如何解决。
In file included from useMVector.cpp
[Error] invalid use of incomplete type 'class MVector<T, size>'
In file included from MVector.cpp
from useMVector.cpp
[Error] declaration of 'class MVector<T, size>'
recipe for target 'useMVector.o' failed
相关代码在这里列出:
useMVector.cpp:
#include <stdlib.h>
#include "MVector.cpp"
using namespace std;
int main() {
return 0;
}
MVector.h:] >>
#ifndef _MVECTOR_ #define _MVECTOR_ #include <iostream> #include <stdlib.h> #include <vector> using namespace std; template<class T, int size> class MVector : public std::vector<T> { public: // constructer: MVector(); // operator=, copy constructor and destructor from std::vector // iterator from std::vector // methodes: // addition with vector template<class T2> MVector<T, size> operator+(const MVector<T2,size>& y); ... }; #endif // _MVECTOR_
MVector.cpp
#include "MVector.h"
template<class T, int size>
MVector<T, size>::MVector() : std::vector<T>::vector(size, 0) {};
template<class T2, class T, int size>
MVector<T,size> MVector<T,size>::operator+(const MVector<T2,size>& y) {
}
我对继承STL向量的类的定义有一些疑问。此类是公开继承自std :: vector的前提,但是我一直从compiter中收到以下错误。我是...
template<class T2, class T, int size>
MVector<T,size> MVector<T,size>::operator+(const MVector<T2,size>& y)