getting strange result after putting get data from DHT11 to a function in header

I am writing a sketch that includes then below header file util.h

Earlier I had code to read DHT11 in the sketch iteself now I have moved it to a separate file.
after moving to separate file I am getting strange result after putting get data from DHT11 to a function in header

#include <dht.h>
namespace util
{

double* getTempHumdata(const int sensorPin)
{

  dht DHT;
  double nums [2];
  int chk = DHT.read11(sensorPin);
  //  int chk = DHT.read(sensorPin);
  int hum;
  double temp;

  int foo [] = { 10, 20, 30 };
  Serial.print("Sensor ");
  Serial.print(sensorPin);
  Serial.print(" ");


  switch (chk)
  {
    case 0:
      hum = (double) DHT.humidity;
      temp = (double) DHT.temperature;
      nums[0] = temp;
      nums[1] = hum;
      Serial.print("Temperature: ");
      Serial.print(nums[0]);
      Serial.print(" Humidity: ");
      Serial.println(nums[1]);
      Serial.print(hum);
      Serial.print(" % ");
      Serial.print(temp);
      Serial.println(" &#38;#38;#38;#8451");
      break;
    case -1: Serial.println(" Checksum error"); break;
    case -2: Serial.println(" Time out error"); break;
    default: Serial.println(" Unknown error"); break;
      return nums;
  }
}
}

I have no clue why is this happening ?

seaurchin: I am getting strange result

I have no clue why is this happening

?

Perhaps if you told us what was strange about the result we would be able to explain why it is happening.

johnwasser: Perhaps if you told us what was strange about the result we would be able to explain why it is happening.

int chk = DHT.read11(sensorPin); returns -1, for which i am printing checksum error, but i do not get chk val as -1 if i am fetching it directly in sketch.

Do you get the same checksum error if you use DHT.read(sensorPin) instead of DHT.read11(sensorPin)? The 'read11' version doesn't include two of the bytes in the checksum because it assumes they are zeroes. That would cause a checksum error if they are not zeroes. The 'read' version does a checksum on all four bytes.