正确使用“使用”使用标准模板 [英] Correct usage of "using" with standard templates

查看:79
本文介绍了正确使用“使用”使用标准模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一些广泛的搜索,似乎无法找到答案

这个 -


使用是否正确使用"使用模板,例如:

使用std :: vector;

或者我是否也需要指定类型:

使用std :: vector< int>;


两者似乎都在工作在我有的编译器上,我找不到任何

文档说哪个是正确的,或者都是正确的?

I''ve done some extensive searching and can''t seem to find an answer to
this -

Is it correct to using "using" with templates, for example:
using std::vector;
Or do I need to specify the type too:
using std::vector<int>;

Both seem to "work" on the compiler I have and I can''t find any
documentation saying which is correct, or are both correct?

推荐答案

jo ************* **@gmail.com 写道:
我做了一些广泛的搜索,似乎无法找到答案
这个 -

使用使用是否正确使用模板,例如:
使用std :: vector;



是的。


或者我也需要指定类型:
使用std :: vector< int>;
I''ve done some extensive searching and can''t seem to find an answer to
this -

Is it correct to using "using" with templates, for example:
using std::vector;

Yes it is.

Or do I need to specify the type too:
using std::vector<int>;



不,你不需要。



-

Ioannis Vranos

http://www23.brinkster.com/noicys


jo * **************@gmail.com 写道:
我做了一些广泛的搜索,似乎无法找到答案
这个 -

使用使用是否正确使用模板,例如:
使用std :: vector;


是。

或者我也需要指定类型:
使用std :: vector< int> ;;


我不确定这应该没关系。此表单保留用于将该类的

成员带入范围,但是您在那里没有指定成员。

声明是否具有所需的效果?你可以使用vector< int>

之后没有''std ::''吗?


另一个有趣的问题,它是否实例化''std :: vector< ; int>''到期

到那个声明?

两者似乎都工作了在我有的编译器上,我找不到任何
文件说哪个是正确的,或者都是正确的?
I''ve done some extensive searching and can''t seem to find an answer to
this -

Is it correct to using "using" with templates, for example:
using std::vector;
Yes.
Or do I need to specify the type too:
using std::vector<int>;
I am not sure this should be OK. This form is reserved for bringing
members of that class into the scope, but you specify no members there.
Does the declaration have the desired effect? Can you use vector<int>
without ''std::'' afterwards?

Another interesting question, does it instantiate ''std::vector<int>'' due
to that declaration?
Both seem to "work" on the compiler I have and I can''t find any
documentation saying which is correct, or are both correct?




我总是使用第一个。到目前为止我没有让我失望...


V



I always use the first one. Hasn''t failed me so far...

V


Victor Bazarov写道:
Victor Bazarov wrote:
或者我是否也需要指定类型:
使用std :: vector< int> ;;
Or do I need to specify the type too:
using std::vector<int>;



我是不确定这应该没问题。此表单用于将该类的
成员带入作用域,但是您在那里没有指定成员。
声明是​​否具有所需的效果?你可以使用vector< int>
而不使用''std ::''吗?

另一个有趣的问题是,它是否实例化了''std :: vector< int>''duebr该声明是什么?


I am not sure this should be OK. This form is reserved for bringing
members of that class into the scope, but you specify no members there.
Does the declaration have the desired effect? Can you use vector<int>
without ''std::'' afterwards?

Another interesting question, does it instantiate ''std::vector<int>'' due
to that declaration?

两者似乎都在工作。在我的编译器上,我找不到任何
文件说哪个是正确的,或者都是正确的?
Both seem to "work" on the compiler I have and I can''t find any
documentation saying which is correct, or are both correct?



我总是使用第一个。到目前为止我没有让我失望......


I always use the first one. Hasn''t failed me so far...



#include< vector>

int main()

{

使用std :: vector< int> ;;


vector< int> vec(10);

}


MINGW:

C:\ c\temp.cpp在函数`int main()'':

6 C:\ c\temp.cpp语句错误在'<''标记之前


C:\ c> cl temp.cpp

Microsoft(R)32位C / C ++优化编译器版本14.00.40904(适用于80x86)


temp.cpp

temp.cpp(6):错误C2873:''std :: vector< _Ty>'':符号不能用于

a使用

-declaration

with

[

_Ty = int

]

temp.cpp(8):错误C2065:''vector'':未声明的标识符

temp.cpp(8) ):错误C2062:输入''int''意外


C:\c>


-

Ioannis Vranos

http:// www23。 brinkster.com/noicys


这篇关于正确使用“使用”使用标准模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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