title: CUDA cudaMemcpu Segmentation fault when copying array of object pointers
body: <p>I am trying to move an array of pointers to the device, where each pointer is pointing to a class object. However, I get a Segmentation fault at the line using cudaMemcpy. I am trying to follow the lines used in this <a href="https://stackoverflow.com/questions/43096660/cudamemcpy-array-of-pointers-where-each-pointer-points-to-an-array">post</a>.</p>
  <p>main.cu</p>
  <pre><code>#include &quot;testclass.cuh&quot;
  #include &lt;iostream&gt;
  
  
  __global__ void printtest(Test* test){
      printf(&quot;HELLO FROM CUDA\n&quot;);
      printf(&quot;CUDA1 : %i\n&quot;, test-&gt;hello);
      Test test2(6);
      printf(&quot;CUDA2 : %i\n&quot;, test2.hello);
      printf(&quot;BYEEE FROM CUDA\n&quot;);
  
  }
  
  int main(){
      printf(&quot;hello\n&quot;);
      Test* test = new Test(512);
      printf(&quot;CPU : %i\n&quot;, test-&gt;hello);
      Test* devtest;
      cudaMalloc(&amp;devtest, sizeof(Test));
      cudaError_t err = cudaMemcpy(devtest, test, sizeof(Test), cudaMemcpyHostToDevice);
      if (err != cudaSuccess) {                                   
          fprintf(stderr, &quot;Error %s at line %d in file %s\n&quot;,             
              cudaGetErrorString(err), __LINE__-3, __FILE__);
      }
      printtest&lt;&lt;&lt;1, 1&gt;&gt;&gt;(devtest);
      cudaDeviceSynchronize();
  
  
  
      printf(&quot;hello2\n&quot;);
      Test** test3 = new Test*[2];
      test3[0] = new Test(12299);
      test3[1] = new Test(234923);
      printf(&quot;CPU : %i\n&quot;, test3[0]-&gt;hello);
      Test** devtest3;
      cudaMalloc(&amp;devtest3, 2*sizeof(Test*));
      printf(&quot;CPU2\n&quot;);
      err = cudaMemcpy(devtest3[0], test3[0], sizeof(Test), cudaMemcpyHostToDevice);
      if (err != cudaSuccess) {                                   
          fprintf(stderr, &quot;Error %s at line %d in file %s\n&quot;,             
              cudaGetErrorString(err), __LINE__-3, __FILE__);
      }
      printf(&quot;CPU3\n&quot;);
      printtest&lt;&lt;&lt;1, 1&gt;&gt;&gt;(devtest3[0]);
      cudaDeviceSynchronize();
  }
  </code></pre>
  <p>testclass.cu</p>
  <pre><code>#include &quot;testclass.cuh&quot;
  
  __host__ __device__ Test::Test(int in){
      hello = in;
  }
  </code></pre>
  <p>testclass.cuh</p>
  <pre><code>class Test {
  public: 
      int hello;
      __host__ __device__ Test(int);
  };
  </code></pre>