等价于 with(from Pascal) 到 C/C++ [英] Equivalent of with(from Pascal) to C/C++
本文介绍了等价于 with(from Pascal) 到 C/C++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Pascal 语言中的 with
在 C/C++ 语言中的等价物是什么?
What is the equivalent of with
from Pascal language in C/C++ language?
with
语句是引用记录字段或对象的字段、属性和方法的简写.
A with
statement is a shorthand for referencing the fields of a record or the fields, properties, and methods of an object.
示例
With (Object) do
begin
Width:=200;
Height:=300;
end;
等价于:
Object.Width=200;
Object.Height=200;
推荐答案
我不认为在 c/c++ 中有任何直接等效的语句.
I don't believe that there is any direct equivalent to that statement in c/c++.
如果您的目标是避免重复输入Object",那么我想您可以使用引用将其映射到较短的名称,例如:
If your objective is to avoid repeatedly typing "Object", then I suppose you could use a reference to map it to a shorter name, such as:
ClassName& o = Object;
o.prop1 = "meep";
o.prop2 = "moop";
但我个人只会在对象"是一个复杂表达式的情况下使用它.例如:
But I would personally only use this in cases where "Object" is a complex expression. E.g.:
ClassName& o = something.getSomeOtherThing().getSomeThirdThing();
o.prop1 = "meep";
o.prop2 = "moop";
这篇关于等价于 with(from Pascal) 到 C/C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文