1

I'd like to define some constants in a c++ program. The excellent boost library has them predefined, and I like to assign my constants these values, e.g. something like

#include <iostream>
#include <boost/units/systems/si/codata/electromagnetic_constants.hpp>

int main(int argc, const char * argv[]) {
    double electron_charge = boost::units::si::constants::codata::e;

    std::cout << electron_charge << std::endl;
    return 0;
}

But this does not work since boost's e is not of type double but of type value_type. How can I access the value in double precision?

DaPhil
  • 1,509
  • 4
  • 25
  • 47

1 Answers1

6

You need to divide the electric charge of the electron by the electric charge unit: Coulomb:

double electron_charge = boost::units::si::constants::codata::e / boost::units::si::coulomb;
Christophe Vu-Brugier
  • 2,645
  • 26
  • 21