Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to underdtand this code...Is it C++11? [duplicate]

Tags:

c++

c++11

I came across one project,where I found some code which I is not understandable to me. I just started with C++, so it seems like a big problem for me. I am providing few lines of my project,which I am not able to understand.

class abc
{
     public:
       //some stuff
       abc();
};

abc::abc()
{
    int someflag = 0;
    //code
    if(someflag == 0)
    {
         do
         {
             //few strcpy operations
             {                 //(My Question)Without any condition braces started
                   //variable initialization
             }
         }while(condition);
    }
}

Now my questions...

  1. What we can achieve by doing this operation?
  2. What is happening in inside braces of do-while loop?
  3. What is the scope of the initialized variables (I mentioned) inside do-while loop?
  4. Is it C++11?

Help me to understand this.

like image 982
someone Avatar asked Dec 25 '22 23:12

someone


1 Answers

  • What we can achieve by doing this operation?

You introduce a scope block for the variables inside.

  • What is happening in inside braces of do-while loop?

See above.

  • What is the scope of the initialized variables (I mentioned) inside do-while loop?

The variables go out of scope at the end of the braces, they're there for that sole reason. One use case I can think of for this is a scoped_lock or something similar to it for multi-threaded applications.

  • Is it C++11?

No.

like image 154
Rapptz Avatar answered Jan 07 '23 23:01

Rapptz