不占用空间的std :: vector的别名 [英] Alias for a std::vector that does not take space

查看:97
本文介绍了不占用空间的std :: vector的别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了std :: vector工作的前一个别名,发现它占用了指针的

空间。我想找到一种方法来为std :: vector做一个别名,

不会占用任何空间。有没有办法做到这一点? (我试过#define Name1

Name2并且它没有编译)

I got the previous alias to std::vector working, and found that it takes up the
space of a pointer. I want to find a way to do an alias to a std::vector that
does not take up any space. Is there any way to do this? (I tried #define Name1
Name2 and it didn''t compile)

推荐答案



Peter Olcott写道:

Peter Olcott wrote:

我得到了std :: vector工作的前一个别名,发现它占用了

空间一个指针。我想找到一种方法来为std :: vector做一个别名,

不会占用任何空间。有没有办法做到这一点? (我试过#define Name1

Name2并且它没有编译)
I got the previous alias to std::vector working, and found that it takes up the
space of a pointer. I want to find a way to do an alias to a std::vector that
does not take up any space. Is there any way to do this? (I tried #define Name1
Name2 and it didn''t compile)



否则没有。也许你应该尝试解释你的问题

而不是。


/ Peter

No there is not. Perhaps you should try to explain your problem
instead.

/Peter


Peter Olcott写道:
Peter Olcott wrote:

我得到了std :: vector工作的前一个别名,发现它占用了

的空间一个指针。我想找到一种方法来为std :: vector做一个别名,

不会占用任何空间。有没有办法做到这一点? (我尝试了#define Name1

Name2并且它没有编译)

I got the previous alias to std::vector working, and found that it takes up the
space of a pointer. I want to find a way to do an alias to a std::vector that
does not take up any space. Is there any way to do this? (I tried #define Name1
Name2 and it didn''t compile)



#define应该有效。 ..但它是一把生硬的锤子:

#define Fred George


struct S {

vector< intGeorge; < br $>
};


s s;


s.Fred.push_back(2);

The #define should have worked... but it''s a blunt hammer:
#define Fred George

struct S {
vector<intGeorge;
} ;

S s;

s.Fred.push_back(2);




Peter Olcott写道:

Peter Olcott wrote:

我得到了std :: vector工作的前一个别名,并发现它占用了指针的

空间。我想找到一种方法来为std :: vector做一个别名,

不会占用任何空间。有没有办法做到这一点?
I got the previous alias to std::vector working, and found that it takes up the
space of a pointer. I want to find a way to do an alias to a std::vector that
does not take up any space. Is there any way to do this?



是:使用方法。例如,


struct {

std :: vector< intm_vec;

std :: vector< int>& alias(){return m_vec; }

std :: vector< intconst& alias()const {return m_vec; }

};


HTH,

Michiel Salters

Yes: use a method. E.g.

struct {
std::vector<intm_vec;
std::vector<int>& alias() { return m_vec; }
std::vector<intconst& alias() const { return m_vec; }
};

HTH,
Michiel Salters

这篇关于不占用空间的std :: vector的别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆