Thread: Pascal "with()" in C++

  1. #1
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96

    Pascal "with()" in C++

    Is there something like Pascal "with" keyword in C++?
    I used it in Pascal this way:

    type Tstructure = record {equals to typedef struct in C++}
    element1: boolean;
    element2: integer; {and so on}
    end;

    var structure: Tstructure;

    procedure viewelements(); {prints contents of the two elements}
    begin
    if structure.element1 then writeln('true') else writeln('false');
    writeln(inttostr(structure.element2));
    end;

    procedure viewelementsUsingWith(); {prints contents of the two elements using with keyword}
    begin
    with structure do begin
    if element1 then writeln('true') else writeln('false');
    writeln(inttostr(element2));
    end;
    end;

    end.

    If you don't know Pascal (but I think everybody here does), I NEED TO ACCESS STRUCTURE ELEMENTS WITHOUT ALWAYS WRITING A STRUCTURE NAME BEFORE "." or "->"

    Please excuse my POOR english...
    Last edited by larry; 09-26-2001 at 12:00 PM.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    1
    struct Tstructure {
    bool element1;
    int element2;
    }

    void viewelements(Tstructure generic){
    if(generic.element1) cout<<"True"
    else cout<<false;
    cout<<generic.element2;
    }

    int main(){
    Tstructure structure;
    structure.element1=TRUE;
    structure.element2=5;
    viewelements(structure);
    }

    ---------
    this works, but this is still a bad way to do this.

    eric

  3. #3
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    In short no, but you can do something like

    char* s = &structure.pos;
    s->x;
    s->y;

  4. #4
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96
    Thanx. Pointer can do the job well.
    Please excuse my poor english...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pascal.... ??? C# ..... ???
    By Hugo716 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 06-08-2006, 01:01 AM
  2. Pascal
    By cogeek in forum Tech Board
    Replies: 32
    Last Post: 11-20-2004, 04:19 AM
  3. C & Pascal Help
    By Dragon227Slayer in forum C Programming
    Replies: 4
    Last Post: 12-01-2003, 09:40 AM
  4. Compares C++ and Pascal
    By Jaguar in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 07-19-2002, 11:28 AM
  5. Pascal Compiler
    By (TNT) in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 04-09-2002, 12:57 AM