对于看到这个问题的人:看看答案并考虑使用:cdecl
为什么下面的代码会给出编译器错误:
prog.cpp: In function ‘int main()’:
prog.cpp:23:4: error: request for member ‘size’ in ‘a’, which is of non-class type ‘RangeVec<int>(RangeVec<int>)’
a.size();
^
我不明白这段代码有什么问题?
#include <iostream>
#include <vector>
template<typename Type>
class RangeVec: public std::vector<Type> {
public:
RangeVec( const RangeVec & v): std::vector<Type>(v){}
RangeVec( const RangeVec && v): std::vector<Type>(std::move(v)) {}
RangeVec( const std::vector<Type> &v)
: std::vector<Type>(v)
{
//std::sort(std::vector<Type>::begin(),std::vector<Type>::end());
}
};
int main(){
std::vector<int> v;
RangeVec<int> b(v);
RangeVec<int> a( RangeVec<int>(b) );
a.size(); // b.size() works ???? why??
}