Object initialization to zero

Dear All,
I have a doubt that what will happen if I try to initialize object of any class with 0.

for example

1
2
3
4
5
6
7
8
9
10
11
  Class Vehicle
  {
    //anything
  }
  main()
  {
    Vehicle v = 0; //or even if written as
    Vehicle v; //declaration
    v=0; //initialization
  }

Thanks in advance.
Why would you want to do that? The example you provided should not even compile.
I can see the sense of initializing a pointer to zero:
Vehicle *v = 0;
Last edited on
That doesn't make much sense. Do you mean initials all members to zero? You could do something like this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

class Foo
{
   int a, b, c;
public:
   Foo( int n ): a( n ), b( n ), c( n ){}
   void Print() { std::cout << a << b << c << std::endl; }
};

int main( int argc, char* argv[] )
{
   Foo Bar = 0;   // Same as Foo Bar( 0 );
   Bar.Print();

   return 0;
}
Topic archived. No new replies allowed.