c++ - Issue with allocating memory for pointers -


i asking similar question earlier. answers got pinpointed mistake not having set aside memory pointer. following piece of code still complains error: cannot convert ‘void*’ ‘double’ in assignment. mean elements in array set aside null?

#include <cmath> #include <cstdlib> #include <fstream> #include <iostream> #include <vector> #include <stdio.h> #include <stdlib.h>  using namespace std; int n = 2;  int main(int argc, char *argv[]) { double *p[n];  for(int = 0; i<n; ++i){     *p[i]=malloc(sizeof(double));    }         *p[0] = 1.0;     *p[1] = 2.0;     cout << p[0] << " " << p[1] <<endl;      *p[0] = 5.0;     *p[1] = 6.0;     cout << p[0] << " " << p[1] <<endl;          return 0; 

}

i need array solve problem have. array needs in global memory (in cuda), needs pointer gpus can read/write from/to.

p[i]=malloc(sizeof(double));

..get rid of '*' dereferencing double type , trying assign malloc() result it.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -