title: How to pass an array to a constructor or a class?
body: <p>I am new to C++, please help me about it.  Thanks alot.</p>
  
  <p>I wanna pass a (new type array) to a class.  but i got message that "c++ terminate called after throwing an instance of bad_alloc"  What does that mean?    Thanks again!!!!</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class test {
    public:
        test (int*, int);
         void check ();
    private :
      int k;
       int *a= new int [k];
  //int a;
  
  };
  
  
  int main()
  {
    //int a1=5,n=4;
    int n=4;
    int *a1= new int[n];
     //int a1[4]={1,2,3,4};
    test haha(a1,n);
    haha.check();
  
      return 0;
  }
  
  
  test::test(int *aa, int kk){
  a=aa;
  k=kk;
  }
  
  void test::check()
  {
   for(int i=0; i&lt;k; i++){
      cout&lt;&lt;a&lt;&lt;" ";
  
   }
  
  }
  </code></pre>