One approach is to make it a pointer, then call the constructor at runtime. For example:
#include <NewSoftSerial.h>
#include <WProgram.h>
#include <WConstants.h>
#include "Thermal.h"
Thermal::Thermal(int RX_Pin, int TX_Pin){
_RX_Pin = RX_Pin;
_TX_Pin = TX_Pin;
_printer = new NewSoftSerial (_RX_Pin, _TX_Pin);
_printer->begin (9600);
}
Thermal::~Thermal(){
delete _printer;
}
// testing
// new and delete operators
void *operator new(size_t size_) { return malloc(size_); }
void* operator new(size_t size_,void *ptr_) { return ptr_; }
void operator delete(void *ptr_) { free(ptr_); }
Thermal * foo;
void setup ()
{
foo = new Thermal (2, 3);
}
void loop () {
foo->_printer->println ("hello, world");
}
and:
#ifndef Thermal_h
#define Thermal_h
#include <NewSoftSerial.h>
#include <WProgram.h>
#include <WConstants.h>
class Thermal{
public:
Thermal(int RX_Pin, int TX_Pin); // constructor
~Thermal(); // destructor
NewSoftSerial * _printer;
private:
int _RX_Pin;
int _TX_Pin;
};
#endif
I tested this and it did output data from pin 3.