Is there any way to perform divisions on a generic type in .net (C++-CLI)? -


i'm trying create simple rolling mean implementation generic numerical type have hit stumbling block:

generic<typename t> public ref class rollingmean { protected:     circularbuffer<t> m_databuffer;     t m_currentsum;  public:     rollingmean(const int numofitems);      t additem(const t newitem);      t currentmean()     {         return m_currentsum / static_cast<float>(m_databuffer.length); // <--- gives me compiler error c2676     } }; 

this gives me compiler error:

1>c:\projects\util\rollingmean.h(21): error c2676: binary '/' : 't' not define operator or conversion type acceptable predefined operator 1>rollingmean.cpp(6): error c2955: 'mathhelpers::rollingmean' : use of class generic requires generic argument list 1>          c:\projects\util\rollingmean.h(9) : see declaration of 'mathhelpers::rollingmean' 

is there way limit generic classes happy numeric operations?

there's no way generics. suggest follow pattern set linq.enumerable class, provides explicit overloads each of numeric types. take enumerable.average, example: provides overloads int, long, float, double, , decimal, no generic overload.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -