vendredi 14 juillet 2017

C++ error: conversion from ‘const Component' to non-scalar type

I'm trying to calculate the distance between two points, but I'm getting an error due to type conversion. Here's my code:

#define m_maxDistance 400.0
...
Name name = interest.getName(); // link to API below

double deltax = pow(std::atof(name[1]) - newNodePosition.getLatitude(), 2);
double deltay = pow(std::atof(name[2]) - newNodePosition.getLongitude(), 2);

double distance = sqrt(deltax - deltay);
distance = std::min (m_maxDistance, distance);

The newNodePosition returns a float. The name[1] is of type Name, defined here.

The compiler is throwing this error (same for name[2]):

error: cannot convert ‘const Component {aka const ndn::name::Component}’ to ‘const char*’ for argument ‘1’ to ‘double atof(const char*)’
   double deltax = pow(std::atof(name[1]) - newNodePosition.getLatitude(), 2);

I read the other posts related to type conversion, but since this type doesn't seem to be standard, I don't know how to solve.

Aucun commentaire:

Enregistrer un commentaire