Results 1 to 20 of 78
Like Tree1Likes

Thread: Летс ми спик фром май харррт

Hybrid View

  1. #1
    Властелин
    Join Date
    Nov 2010
    Posts
    1,155
    Rep Power
    15
    Quote Originally Posted by it-ogo View Post
    Code:
    Esperanto::Esperanto() { 
      char* dest=(char*) this; 
      idLang Lang=idEnglish;
      while(dest-(char*)this<=sizeof(*this)) {
        *dest++*= *(((char*)&::Languages[Lang])+rand()%sizeof(Languages[Lang]));
        if ((Lang = (idLang)((int)Lang + 1)) > idChinese) Lang=idEnglish;
      }
      for(int i=0; i<nRules; i++) if (GrammarRules[i]->Size>3) GrammarRules[i]=NULL;
    }
    A few corrections...

  2. #2
    Завсегдатай it-ogo's Avatar
    Join Date
    Jan 2009
    Location
    Ukraine
    Posts
    3,048
    Rep Power
    29
    Quote Originally Posted by Eric C. View Post
    A few corrections...
    Code:
    #define self this
    idLang operator ++(idLang &, int);
    
    //etc...
    "Россия для русских" - это неправильно. Остальные-то чем лучше?

  3. #3
    Властелин
    Join Date
    Nov 2010
    Posts
    1,155
    Rep Power
    15
    Quote Originally Posted by it-ogo View Post
    Code:
    #define self this
    idLang operator ++(idLang &, int);
    
    //etc...
    Ok... then:

    Code:
    Esperanto::Esperanto() { 
      char* dest=(char*) self; 
      idLang Lang=idEnglish;
      while(dest-(char*)self<=sizeof(*self)) {
        *dest++*= *(((char*)&::Languages[Lang])+rand()%sizeof(Languages[Lang]));
        if (++Lang > idChinese) Lang=idEnglish;
      }
      for(int i=0; i<nRules; i++) if (GrammarRules[i]->Size>3) GrammarRules[i]=NULL;
    }
    But:

    1. No code like "this*", in this case macros won't let you get away with a syntax error.
    2. No code like "<pointer_name>*" when dereferencing the pointer. That's just wrong and gives you a syntax error as well.
    3. It's generally recommended you define return types of such overloaded operators as "<class_name>&", ie:
    Code:
    idLang& operator ++(idLang &, int);
    That allows you to avoid an unnecessary (and potentially expensive) call of the copy constructor.

  4. #4
    Завсегдатай it-ogo's Avatar
    Join Date
    Jan 2009
    Location
    Ukraine
    Posts
    3,048
    Rep Power
    29
    Ви ар спикинг фром аувер харт.

    Quote Originally Posted by Eric C. View Post
    Ok... then:
    1.
    2.
    Agreed. Mea culpa.


    3. It's generally recommended you define return types of such overloaded operators as "<class_name>&", ie:
    Code:
    idLang& operator ++(idLang &, int);
    That allows you to avoid an unnecessary (and potentially expensive) call of the copy constructor.
    Hmmm... Actually I meant that idLang is enum rather than class. Otherwise we should invent something very special for "Languages[Lang]".
    "Россия для русских" - это неправильно. Остальные-то чем лучше?

  5. #5
    Властелин
    Join Date
    Nov 2010
    Posts
    1,155
    Rep Power
    15
    Quote Originally Posted by it-ogo View Post
    Hmmm... Actually I meant that idLang is enum rather than class.
    I see. Then it's quite ok.

    Quote Originally Posted by it-ogo View Post
    Otherwise we should invent something very special for "Languages[Lang]"
    Like "operator int()"?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Russian Lessons                           

Russian Tests and Quizzes            

Russian Vocabulary