美文网首页
使用类模板

使用类模板

作者: 大啸 | 来源:发表于2021-04-03 15:40 被阅读0次

#include <iostream>

#include <string>

#include <vector>

template <int M, int K, int S>

struct MksUnit

{

enum

{

metre = M,

kilogram = K,

second = S

};

};

template <typename MksUnit>

class Value {

private:

long double mag{ 0.0 };

public:

explicit Value(const long double m) : mag(m) {}

long double getValue() const

{

return mag;

}

};

using Monentum = Value<MksUnit<1, 1, -1>>;

using Force = Value<MksUnit<1, 1, -2>>;

class STC

{

public:

void applyMTSB(const Monentum& implusValue)

{

std::cout << implusValue.getValue() << std::endl;

}

};

int main()

{

STC control;

Monentum mom { 13.75 };

control.applyMTSB(mom);

return 0;

}

相关文章

网友评论

      本文标题:使用类模板

      本文链接:https://www.haomeiwen.com/subject/ghdhkltx.html