Edit
I decided to move forward despite errors. Here's how I remade my header file:
#ifndef Devices_h
#define Devices_h
/* Initial build for MCUOS
Anybody can edit this according to their device needs */
#include "Arduino.h"
template < typename datatype>
class Device_Handler
{
// a class to handle devices
public:
virtual void write_to_device(datatype *send_data)= 0; // write data to device
virtual void read_from_device(datatype *store_location)= 0 ; // read data from device to location
virtual void clear_device() = 0; // clear device state
};
class Serial_Handler:public Device_Handler<char*>
{
public:
void write_to_device(char *send_data);
void read_from_device(char *store_location);
void clear_device();
};
void Serial_Handler::write_to_device(char *send_data){
Serial.println(*send_data);
}
void Serial_Handler::read_from_device(char *store_location){
*store_location = Serial.read();
}
void Serial_Handler::clear_device(){
Serial.flush();
}
#endif
Here's the sketch code:
#include <Devices.h>
Serial_Handler myserial;
char storage = '\0';
char test_string[] = "Hello";
void setup() {
Serial.begin(9600);
myserial.write_to_device(test_string);
myserial.read_from_device(&storage);
}
void loop() {
// put your main code here, to run repeatedly:
}
(I know that the code up there may also be faulty)
and errors come up:
Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"
Devices_Test:3:16: error: cannot declare variable 'myserial' to be of abstract type 'Serial_Handler'
Serial_Handler myserial;
^~~~~~~~
In file included from C:\Users\<smbdy>\Documents\Arduino\Devices_Test\Devices_Test.ino:1:0:
C:\Users\<smbdy>\Documents\Arduino\libraries\Devices/Devices.h:19:7: note: because the following virtual functions are pure within 'Serial_Handler':
class Serial_Handler:public Device_Handler<char*>
^~~~~~~~~~~~~~
C:\Users\<smbdy>\Documents\Arduino\libraries\Devices/Devices.h:14:16: note: void Device_Handler<datatype>::write_to_device(datatype*) [with datatype = char*]
virtual void write_to_device(datatype *send_data)= 0; // write data to device
^~~~~~~~~~~~~~~
C:\Users\<smbdy>\Documents\Arduino\libraries\Devices/Devices.h:15:16: note: void Device_Handler<datatype>::read_from_device(datatype*) [with datatype = char*]
virtual void read_from_device(datatype *store_location)= 0 ; // read data from device to location
^~~~~~~~~~~~~~~~
exit status 1
cannot declare variable 'myserial' to be of abstract type 'Serial_Handler'
How should I resolve this?