user68143: I am able to move motors using AfMotor Shield Library. ( https://github.com/adafruit/Adafruit-Motor-Shield-library )
Like :
AF_DCMotor insertionMotor(1);
AF_DCMotor pumpMotor(2);

void setup()
{
  insertionMotor.setSpeed(255);
  pumpMotor.setSpeed(255);
  insertionMotor.run(RELEASE);
  pumpMotor.run(RELEASE);
  insertionMotor.run(FORWARD);
  pumpMotor.run(FORWARD);
}

But if I want to write it like this, only the motor with the template expansion that I called last works.
enum class direction {
  FRW = 0x01,
  BCKW,
};

template<int n, direction type>
class Motor : public AF_DCMotor {

public:

  Motor() : AF_DCMotor(n) {
    setSpeed(255);
    run(RELEASE);
    run(type);
  }
};
Motor<1, direction::FRW> fanMotor;
Motor<2, direction::FRW> pumpMotor;

Only the pumpmotor is running. Or if I call the fanMotor after the pumpMotor, it still works.If I remove pumpmotor and leave only fanMotor, the fanMotor also works. Is there something I overlooked?

user7508: Your code gives me a compiler error: in
run(type);

the run() method expects a uint8_t, but it is given a direction.
Adding an explicit cast to uint8_t makes it compile.
Now, as a general rule, I would advice you to never touch the hardware
in a constructor. The problem is, if you create a global object (like
you are doing here), the constructor gets called before main(), thus
before the Arduino core has had a chance to initialize the hardware. If
your constructor touches any hardware register, this may conflict with
the initialization the core is going to perform right at the start of
main().
The usual idiom for doing any hardware initialization is to define in
your object a method called begin(), and call it from setup():
template<int n, direction type>
class Motor : public AF_DCMotor {
public:
  Motor() : AF_DCMotor(n) {}

  void begin() {
    setSpeed(255);
    run(RELEASE);
    run((uint8_t) type);
  }
};


68143: <p>I am able to move motors using AfMotor Shield Library. ( <a href="https://github.com/adafruit/Adafruit-Motor-Shield-library" rel="nofollow noreferrer">https://github.com/adafruit/Adafruit-Motor-Shield-library</a> )</p>
<p>Like :</p>
<pre><code>AF_DCMotor insertionMotor(1);
AF_DCMotor pumpMotor(2);

void setup()
{
  insertionMotor.setSpeed(255);
  pumpMotor.setSpeed(255);
  insertionMotor.run(RELEASE);
  pumpMotor.run(RELEASE);
  insertionMotor.run(FORWARD);
  pumpMotor.run(FORWARD);
}
</code></pre>
<p>But if I want to write it like this, only the motor with the template expansion that I called last works.</p>
<pre><code>enum class direction {
  FRW = 0x01,
  BCKW,
};

template&lt;int n, direction type&gt;
class Motor : public AF_DCMotor {

public:

  Motor() : AF_DCMotor(n) {
    setSpeed(255);
    run(RELEASE);
    run(type);
  }
};
Motor&lt;1, direction::FRW&gt; fanMotor;
Motor&lt;2, direction::FRW&gt; pumpMotor;
</code></pre>
<p>Only the pumpmotor is running. Or if I call the fanMotor after the pumpMotor, it still works.If I remove pumpmotor and leave only fanMotor, the fanMotor also works. Is there something I overlooked?</p>
 7508: <p>Your code gives me a compiler error: in</p>
<pre class="lang-cpp prettyprint-override"><code>run(type);
</code></pre>
<p>the <code>run()</code> method expects a <code>uint8_t</code>, but it is given a <code>direction</code>.
Adding an explicit cast to <code>uint8_t</code> makes it compile.</p>
<p>Now, as a general rule, I would advice you to never touch the hardware
in a constructor. The problem is, if you create a global object (like
you are doing here), the constructor gets called before <code>main()</code>, thus
before the Arduino core has had a chance to initialize the hardware. If
your constructor touches any hardware register, this may conflict with
the initialization the core is going to perform right at the start of
<code>main()</code>.</p>
<p>The usual idiom for doing any hardware initialization is to define in
your object a method called <code>begin()</code>, and call it from <code>setup()</code>:</p>
<pre class="lang-cpp prettyprint-override"><code>template&lt;int n, direction type&gt;
class Motor : public AF_DCMotor {
public:
  Motor() : AF_DCMotor(n) {}

  void begin() {
    setSpeed(255);
    run(RELEASE);
    run((uint8_t) type);
  }
};
</code></pre>
