简体   繁体   中英

C++ template class as argument of a function

There is a class library (I cannot/should not change) defined in MIDI.h:

template<class SerialPort, class _Settings = DefaultSettings>
class MidiInterface
{
      ...

I want to use this class as argument. Question question is a duplicate, however I still get a compilation error.

My own header class file looks like:

#include <MIDI.h>

class M
{
  public:
    void setup();
    void run();

  private:
    void printMessage(const MidiInterface<SerialPort, _Settings>&
          midiInterface);
};

I get the following errors:

In file included from sketch\\M.cpp:1:0:

M.h:10: error: 'MidiInterface' does not name a type

 void printMessage(const MidiInterface<SerialPort, _Settings>& midiInterface);

                         ^

M.h:10: error: expected ',' or '...' before '<' token

 void printMessage(const MidiInterface<SerialPort, _Settings>& midiInterface);

                                      ^

exit status 1
'MidiInterface' does not name a type

How can I change the code so it compiles?

It looks like MIDI.h in this code puts everything in a namespace. If that's what you're using, try MIDI_NAMESPACE::MidiInterface<SerialPort, _Settings> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM