Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

Beginner's Question: with statement in C++

I recently migrate from Pascal. But I can't find anything like the Pascal "with" statement in the C++ online help. How to do this in C++?
0
sccheung
Asked:
sccheung
1 Solution
 
David MacDonaldChargé de projet processus d’affaires et systèmes TICommented:
What was the "with " statement doing?...
0
 
AlexVirochovskyCommented:
Or, in C/C++ no "with" statement.
Whan can be equivalent?
If you use some structure/class/pointer, you use "->"/"."
  contsruction.
In Pascal: (psevdocode)

with MyFile
  .Open
  .read
  .Close
End with

In C++
  ifstream in("myfile.dat");
  in.getline(...);

or MyClass *myClass;

  myClass->Open(...);
  myClass->read();
  myClass->Close();

I hope, it helps. Alex
0
 
nietodCommented:
yeah, there really is no equivalent, which is actually good. Pascal's with statement was a mistake that leads to confussion an problems.  This one of the rare times when C++ has a syntractic advantage of Pascal

In a sense, C++'s member functions are similar to Pascal's "with".  This is because a member fucntion can access all the data members of an object (class or structure) without having to explicitly dereference the "this" pointer to get to the data members.
0
 
sccheungAuthor Commented:
It's fine. I can use copy and paste instead. But since the answer didn't "solve" the question, (because there is no solution in this case) I can't give a very high grade.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now