C++ 不完整类型的无效使用';类别…';STL向量

C++ 不完整类型的无效使用';类别…';STL向量,c++,vector,compiler-errors,stl,stdvector,C++,Vector,Compiler Errors,Stl,Stdvector,我对继承STL向量的类的定义有一些疑问。这个类被支持从std::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.c

我对继承STL向量的类的定义有一些疑问。这个类被支持从std::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中包含的文件中的

[错误]不完整类型“class MVector”的使用无效
在MVector.cpp中包含的文件中
来自useMVector.cpp
[错误]声明“类MVector”
目标“useMVector.o”的配方失败
此处列出了相关代码:

useMVector.cpp:

#include <stdlib.h>
#include "MVector.cpp"

using namespace std;

int main() {
    return 0;
}
#包括
#包括“MVector.cpp”
使用名称空间std;
int main(){
返回0;
}
MVector.h:

#pragma once

template<typename T>
class A
{
  A();
};

#include "A_impl.h"
template<typename T>
A::A() {}
\ifndef\u MVECTOR_
#定义_MVECTOR_
#包括
#包括
#包括
使用名称空间std;
模板
类MVector:public std::vector{
公众:
//施工人员:
MVector();
//运算符=,从std::vector复制构造函数和析构函数
//来自std::vector的迭代器
//方法:
//矢量加法
模板
MVector运算符+(常量MVector&y);
...
};
#endif/\u MVECTOR_
MVector.cpp

#包括“MVector.h”
模板
MVector::MVector():std::vector::vector(大小,0){};
模板
MVector MVector::operator+(const MVector&y){
}
A\u impl.h:

#pragma once

template<typename T>
class A
{
  A();
};

#include "A_impl.h"
template<typename T>
A::A() {}
模板
A::A(){}
您可以根据自己的约定命名
A_impl.h
,有些代码库使用类似
A.ipp
的名称

std::vector
(以及大多数其他标准库类)派生很少合适,您应该使用
std::vector
成员

A\u impl.h:

#pragma once

template<typename T>
class A
{
  A();
};

#include "A_impl.h"
template<typename T>
A::A() {}
模板
A::A(){}
您可以根据自己的约定命名
A_impl.h
,有些代码库使用类似
A.ipp
的名称


std::vector
(以及大多数其他标准库类)派生很少合适,您应该使用
std::vector
成员来代替。

谢谢您的回答。你不从STL类派生是有原因的,还是仅仅是惯例?它们没有虚拟析构函数,所以这样做并不完全安全,请参见“谢谢你的回答”。您不从STL类派生是因为什么原因,还是因为它只是一种约定?它们没有虚拟析构函数,所以这样做并不完全安全,请参阅