Hello fellow coders,
I am trying to create a template that behaves differently
if it is give a primative type vs a class. I should be easy
enough but my brain seems to be stuck in neutral.
Here is the general problem:
Code:
template< class T, class S>
struct Node
{
Node* MyNode;
T Value;
}
template< class T, class S>
class Myclass
{
T GetValue();
bool operator== (T rhs);
Node node;
}
// In the case that T is a class, T will look somethink like this.
template< class T, class S>
class MyVector
{
int size;
float length;
S value;
}
Here are the requirements.
If T is a a primative (int, long, float, double, char...), S will be a primative of the same type
GetValue will return the value of classInst1.node.value
The operator== will compare classInst1.node.value == classInst2.node.value
If T is a class, S will be a primative.
GetValue will return the value of classInst1.node.value
The operator== will compare classInst1.node.<T>value.value == classInst2.node.<T>value.value
so I could have a program like this:
Code:
main()
{
Myclass<int, int> Foo1;
Myclass<int, int> Foo2;
Myclass<MyVector, float> Bar1;
Myclass<MyVector, float> Bar2;
int myInt = Foo1.GetValue(); //returns Foo1.node.value
MyVector myVect = Bar1.GetValue(); //returns Bar1.node.value
if ( Foo1 == Foo2 ){} //compares Foo1.node.value == Foo2.node.value
if ( Bar1 == Bar2 ){} //compares Bar1.node.value.value == Bar2.node.value.value
}
Thank in advance for any help.
byteherder