There was a post here about generic code, making an impressive effort and attempt to solve that with template methods.
The main drawback of the template methods presented here, is that a template method can not be a virtual method and thus can not be used in building a class library.
Hence, I suggest what is in my opinion a more usable approach to building libraries. It is slightly better than a previous version I had that used 3 classes, this one uses only two classes, where IMHO one can be bypassed if MQ will make a slight effort to improve the methods selection.
For now, there is a need for one class that takes all the reference data, and one extension to use only for those methods that the user pass a T type in the method signature. The number of signatures for each method is 1 (passing the value/pointer to the reference base method).
IMHO MQ can make it true generic, by saving us from the need to write a second class for values by making the reference types accept primitive value/pointer:
1. Allow to pass a primitive literal value to a reference method (like C++ does) if it's the only signature that is available.
2. Allow to pass an object pointer to a reference method
As you can see from the code example, QueueVal only passes the primitive value literal or pointer to the QueueBase reference method, so there might be no big issue for MQ to allow that, unless I miss something.
But without MQ's effort, this is my preffered solution for a true generic library
So you can omit the template argument on each function then.
Oh yes, if you place the method definitions inside the class {} brackets. But as I declared them outside, you have to specify them because the class name is CQueuBase<int> for it to be distinguished from another class CQueuBase<double> etc. Like in C++ btw.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
There was a post here about generic code, making an impressive effort and attempt to solve that with template methods.
The main drawback of the template methods presented here, is that a template method can not be a virtual method and thus can not be used in building a class library.
Hence, I suggest what is in my opinion a more usable approach to building libraries. It is slightly better than a previous version I had that used 3 classes, this one uses only two classes, where IMHO one can be bypassed if MQ will make a slight effort to improve the methods selection.
For now, there is a need for one class that takes all the reference data, and one extension to use only for those methods that the user pass a T type in the method signature. The number of signatures for each method is 1 (passing the value/pointer to the reference base method).
IMHO MQ can make it true generic, by saving us from the need to write a second class for values by making the reference types accept primitive value/pointer:
1. Allow to pass a primitive literal value to a reference method (like C++ does) if it's the only signature that is available.
2. Allow to pass an object pointer to a reference method
As you can see from the code example, QueueVal only passes the primitive value literal or pointer to the QueueBase reference method, so there might be no big issue for MQ to allow that, unless I miss something.
But without MQ's effort, this is my preffered solution for a true generic library