returning pointers from functions?

Hi

I am getting the following compile error when compiling the code below:

1
2
3
func_ptr.cpp: In function ‘const double* f1(const double*, int)’:
func_ptr.cpp:11:17: error: cannot convert ‘double’ to ‘double*’ in initialization
   double * d{0.0};


Can anybody help me understand why, as I thought I was returning a pointer ?

1
2
3
4
5
6
7
8
9
10
11
12
13
  1 #include <iostream>
  2 
  3 // f1() returns a pointer to a double
  4 const double * f1(const double [], int);
  5 
  6 int main() {
  7   return 0;
  8 } 
  9 
 10 const double *f1 (const double p[], int i) {
 11   double * d{0.0};
 12   return d;
 13 }
The error points at line 11. The error says "in initialization". Line 11 is not the return. Line 11 is the line before the return.

The complaint here is that you're trying to create a pointer-to-double, and you're trying to giving it the initial value of 0.0

That makes no sense. A pointer cannot have a value of 0.0

ok, got it. so obvious in the end. thanks for replying.
Last edited on
Topic archived. No new replies allowed.