两种constructor

#include <iostream>
#include <string.h>
using namespace std;

class Hello
{
private:
  int a;
public:
  Hello();
};

Hello::Hello()
{
  a = 5;
  cout << "a is: " << a << endl;
}


int main()
{
  Hello sayhello;

  return 0;
}





#include <iostream>
#include <string.h>
using namespace std;

class Hello
{
private:
  int a;
public:
  Hello();
  { a = 5;
    cout << "a is: " << a << endl;
  } 
};


int main()
{
  Hello sayhello;

  return 0;
}

  

posted on 2019-08-16 13:07  cdekelon  阅读(68)  评论(0)    收藏  举报

导航