Who can I force compilation to used dedicaced function instead of Template function?


I currently working on an external ram manager library.
It's not only offering method to read/write in/to ram like several other library.
But this librairy taking care of automatic addressing inner the external ram ship.
With this librairy you can use dynamic addressing during execution. You dont have to calculate the space you need and determine the place you go into the external ram ship.
The best point : whatever the place you need, you just have to keep a 16bits address, only 2 bytes. Even if you need an array of hundred of double, it's just use 16 bits of arduino ram.

All source code are available there :

But I have a problem :
To make difference between standard variable and external ship variable but keeping code readable, I define _uint16_t class similar as uint16_t to define 16 bits variable into external ram.
And use same way with _uint32_t / uint32_t... int16_t, double, float... all numerical variable.
All _uint16_t, _double, etc... (note the underscore caractere) inherit from ram_vars

class _uint16_t : public ram_vars
class _uint32_t : public ram_vars
class _double : public ram_vars

I try to overload arithmetic operator with arithmetic variable and ram_vars variable too.
So, I have define method using ram_vars parameter and method that use Template parameter.

ram_vars &operator+=(  const ram_vars &val )
template <typename T>   ram_vars &operator+=( const T val )

And I have trouble with this point : all operation goes with template method even if specific method have been defined.

How can I force called method when operating with ram_vars operand ?

_uint16_t varA = _uint16_t();
varA.alloc();            // allocating space in external ram ship and retrieving address

_uint16_t varB = _uint16_t();
varB.alloc();           // allocating space in external ram ship and retrieving address

varA = 12;
varB = 5;

varA += 6;         // now, varA = 18 : using template method. OK
varA += varB;   // using template method instead of specific methode...

Does someone can help me ?

use a function name different than the name of the template function (e.g. my_ram_vars)

Try a web search for "Template Specialization". It might be what you need.

thanks for this proposition but I dont think it's suitable for the use I need.
I try to overload operator so, the name can not be change

Thanks for this tips.
I have made some search and found some topic.
I understand the logic of how can I "overload" a generic methode when a specific type is pass through parameter.
But I don't know if I use it right :

here my base class, with generic method (all other method and members have been remove to make clear)

class ram_vars {
    template <class T> ram_vars &operator=( const T &val ){
      Serial.println( "= template  " );
      RAM.doMath( opCode_affectation, val );
      return( *this );

here my specialized template outside of the class :

template <> ram_vars& ram_vars::operator=<ram_vars>( const ram_vars &val ){
      Serial.println( "= ram_vars  " );
      return( *this );

but I get linker error. What I have miss ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.