D
DeMarcus
Hi,
I'm using extended const like the following.
// ExtConst.hpp
#ifndef EXT_CONST
#define EXT_CONST
#include <string>
struct ExtConst
{
ExtConst( double value, const std::string& description )
: value(value), description(description) {}
const double value;
const std::string description;
};
#endif
// Constants.hpp
#ifndef CONSTANTS
#define CONSTANTS
#include "ExtConst.hpp"
const ExtConst PI( 3.1415, "Circumference / diameter." );
const ExtConst E( 2.71828, "Euler's constant." );
#endif
// Now I use ExtConst.hpp in several files since const in front of
ExtConst ensures internal linkage (§7.1.1/7).
// An example.
#include "Constants.hpp"
int main()
{
std::cout << "Constant: " << E.value
<< " Description: " << E.description << std::endl;
}
Are constants made up of whole classes or structures common practice? Do
you use that in your projects, and if not, is there a reason?
Thanks,
Daniel
I'm using extended const like the following.
// ExtConst.hpp
#ifndef EXT_CONST
#define EXT_CONST
#include <string>
struct ExtConst
{
ExtConst( double value, const std::string& description )
: value(value), description(description) {}
const double value;
const std::string description;
};
#endif
// Constants.hpp
#ifndef CONSTANTS
#define CONSTANTS
#include "ExtConst.hpp"
const ExtConst PI( 3.1415, "Circumference / diameter." );
const ExtConst E( 2.71828, "Euler's constant." );
#endif
// Now I use ExtConst.hpp in several files since const in front of
ExtConst ensures internal linkage (§7.1.1/7).
// An example.
#include "Constants.hpp"
int main()
{
std::cout << "Constant: " << E.value
<< " Description: " << E.description << std::endl;
}
Are constants made up of whole classes or structures common practice? Do
you use that in your projects, and if not, is there a reason?
Thanks,
Daniel