Retrieve CUDA variable from c++ class

I have a normal c++ class foo with a variable that is set via constructor, the variable is a pointer used in cuda memory allocation, in constructor the variable is accesible, but in getter the variable gives memory access error:

#include <cuda_runtime_api.h>
#include "cuda.h"
#include "cuda_runtime.h"

class foo{
      float *my_arr;
      foo(float *arr):my_arr(arr){
        float a = my_arr[0];  --> This works

      __global__ float* foo::getMyArr(){
        float a = my_arr[0];  --> This fails
        return *my_arr;

void main(){
   int N = 1000;
   float *arr;
   cudaMallocManaged(&arr, N*sizeof(float));

   foo myfoo(arr);
   float* value = myfoo.getMyArr();

I’m using cuda 10.0, Ubuntu 18.04, does anybody knows how to have reference to cuda variables in c++ classes? or what kind of mistake I have?

This code won’t compile.