template <int m, // exponent for mass
int d, // exponent for distance
int t> // exponent for time
class Units
{
public:
explicit Units(double initVal = 0) : val(initVal) {
}
double value() const {
return val; }
double &value() {
return val; }
private:
double val;
};
void test_dimension()
{
Units<1, 0, 0> m; // m is of type mass
Units<0, 1, 0> d; // d is of type distance
Units<0, 0, 1> t; // t is of type time
cout << sizeof(m) << endl;
}
Dimensional Analysis in C++ by Template
猜你喜欢
转载自blog.csdn.net/alpha_007/article/details/114369194
今日推荐
周排行