Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of with(from Pascal) to C/C++

What is the equivalent of with from Pascal language in C/C++ language?

A with statement is a shorthand for referencing the fields of a record or the fields, properties, and methods of an object.

Example

With (Object) do
begin
   Width:=200;
   Height:=300;
end;

Is Equivalent with:

Object.Width=200;
Object.Height=200;
like image 721
user558126 Avatar asked Dec 16 '25 20:12

user558126


1 Answers

I don't believe that there is any direct equivalent to that statement in c/c++.

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";
like image 136
Edward Loper Avatar answered Dec 19 '25 13:12

Edward Loper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!