本文介绍了模板矢量,不完整类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在迁移一些std :: vectors而不是使用模板,但我在结构声明中得到了

不完整的类型错误。


#include< vector>


template< typename T>

class Vec:public std :: vector< T {

public:

Vec():Vec< T>(){}

Vec(int s):std :: vector< ; T>(s){}

T& operator [](int i){return at(i); }

const T& operator [](int i)const {return at(i); }

};

typedef Vec< doublevecdbl;

typedef Vec< vecdblmatdbl;

#include" matvec .h"

//就在上面


typedef vecdbl memvec;


struct felt

{

...

memvec m; //< - 不完整类型错误

Hi,
I am migrating some std::vectors to use a template instead, but I get
an incomplete type error in a struct declaration.

#include <vector>

template < typename T >
class Vec : public std::vector< T {
public:
Vec():Vec<T>() { }
Vec( int s ) : std::vector<T>(s) { }
T& operator[](int i) { return at(i); }
const T& operator[](int i ) const { return at(i); }
};
typedef Vec<doublevecdbl;
typedef Vec<vecdblmatdbl;
#include "matvec.h"
// that is it above

typedef vecdbl memvec;

struct felt
{
...
memvec m; // <- incomplete type error

推荐答案



我不明白Vec():Vec< T>(),可能你是编译器
因为这个问题,
最终没有成为Vec< Tincomplete课程



-

Greg Comeau / 20年的Comeauity! Intel Mac Port现在为alpha!

Comeau C / C ++ ONLINE ==

世界级编译器:令人惊叹的C ++,惊人的C99,很棒的C90。

Comeau C / C ++与Dinkumware你的图书馆......你试过吗?

I don''t understand Vec():Vec<T>() and probably you''re compiler
doesn''t either eventually makeing Vec<Tincomplete classes
because of that problem.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware''s Libraries... Have you tried it?



我不明白Vec():Vec< T>(),可能你是编译器
不会''由于这个问题,最终要么成为Vec< Tincomplete classes


I don''t understand Vec():Vec<T>() and probably you''re compiler
doesn''t either eventually makeing Vec<Tincomplete classes
because of that problem.



另外在另一个方面:std :: vector未被写为

派生自。

-

Greg Comeau / 20年的Comeauity! Intel Mac Port现在为alpha!

Comeau C / C ++ ONLINE ==

世界级编译器:令人惊叹的C ++,惊人的C99,很棒的C90。

Comeau C / C ++与Dinkumware你的图书馆......你试过吗?

Also on a different aspect: std::vector was not written to be
derived from.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware''s Libraries... Have you tried it?




Vec( ):std :: vector< T>(){}

Vec() : std::vector<T>() {}



& operator [](int i){return this-> at(i); }

& operator[](int i) { return this->at(i); }



const T& operator [](int i)const {return this-> at(i); }

const T& operator[](int i ) const { return this->at(i); }



最佳


Kai-Uwe Bux


Best

Kai-Uwe Bux


这篇关于模板矢量,不完整类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-08 18:39