C ++有“with”关键字像Pascal? [英] Does C++ have "with" keyword like Pascal?
本文介绍了C ++有“with”关键字像Pascal?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
和
关键字可以用来快速访问记录的字段。
任何人都知道C ++是否有类似的东西?
例如:
我有一个指针有许多字段,我不想类型像这样:
if(pointer-> field1)&& (pointer-> field2)&& ...(pointer-> fieldn)
我真正想要的是这样的C ++:
with(pointer)
{
if(field1)&& (field2)&& .......(fieldn)
}
解决方案>
在C ++中,您可以将代码放在由指针
引用的类的方法中。在那里你可以直接引用成员而不使用指针。让它 inline
,你几乎可以得到你想要的。
with
keyword in Pascal can be use to quick access the field of a record.
Anybody knows if C++ has anything similar to that?
Ex: I have a pointer with many fields and i don't want to type like this:
if (pointer->field1) && (pointer->field2) && ... (pointer->fieldn)
what I really want is something like this in C++:
with (pointer)
{
if (field1) && (field2) && .......(fieldn)
}
解决方案
In C++, you can put code in a method of the class being reference by pointer
. There you can directly reference the members without using the pointer. Make it inline
and you pretty much get what you want.
这篇关于C ++有“with”关键字像Pascal?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文