Using a template to pass a variable to a library

(deleted)

For templated class, the declaration and definition must be in the same file.

Please describe your problem again, and possibly give an example of what you want to achieve. For example

ExternalLibraryObject<MyVariable> myObject;

is "ExternalLibraryObject" an templated class as well or you just want an array of "ExternalLibraryObject"?

(deleted)

avgprogrammer:
Yes, ExternalLibraryObject is a templated class and from my sketch I will be calling my library with different variables which will spawn multiple objects with different properties based on that variable. So the only way to get the variable for the object decoration is as above but I may call multiple instances which is why I need to use the template. If that makes sense.

See if this works for you:

//remember declaration and definition for template class must be in same file.
//if the function is short you could inline it.

template<typename T>
class ExternalLibraryObject
{
};

//declaration
namespace ct
{
    template<typename T>
    class my_device
    {
        public:
            my_device(uint8_t pin);
            virtual void init();
            virtual inline void short_function()
            {
                //doing something very fast;
            }
        private:
            ExternalLibraryObject<T> myObject;
    };

}

//definition
template<typename T>
ct::my_device<T>::my_device(uint8_t pin) :
        myObject()
{

}

template<typename T>
void ct::my_device<T>::init()
{

}


void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Keep in mind that templated stuffs consume consideration amount of program space, as a new class (not instance) is created for each different templated type. Don't use it on AVR.

(deleted)