Single line class declaration and instantiation

152 Views Asked by At

I've stumbled upon code using the following syntax.

int main(){    
  class foo{
    public:
      int x;
      foo(int y){x=y;}
  }
  * bar = new foo(1);    
}

Is there any purpose/consequence of using it compared to the more common

int main(){    
  class foo{
    public:
      int x;
      foo(int y){x=y;}
  };

  foo * bar = new foo(1);    
}
1

There are 1 best solutions below

5
On BEST ANSWER

This is probably a matter of opinion but I think the first method is poor coding practice.

  1. It does not impact run time behavior.
  2. It makes the code harder to read.