Original Post
I know that if I create a template class, I need to include the member function definitions inside the .h file as well but I was wondering if I need to define ALL member functions in the .h file or just the ones that use the typename defined by the template keyword?
Is the below example ok or do I need to define all functions in the header file even if "T" is not touched by 3 of the member functions/constructors/destructors?
NOTE: Yes, I know the below code is not functional, it does not compile and there are errors in it (e.g. T value[];), it is an example only and is used to illustrate my question
[source lang="cpp"]
template
class TestClass
{
TestClass();
~TestClass();
void DoSomethingThatDoesNotTouchT();
T GetValue(int x)
{
return value[x];
}
void SetValue(int x, T v)
{
value[x] = v;
}
private:
T value[];
};
[/source]
Is the below example ok or do I need to define all functions in the header file even if "T" is not touched by 3 of the member functions/constructors/destructors?
NOTE: Yes, I know the below code is not functional, it does not compile and there are errors in it (e.g. T value[];), it is an example only and is used to illustrate my question
[source lang="cpp"]
template
class TestClass
{
TestClass();
~TestClass();
void DoSomethingThatDoesNotTouchT();
T GetValue(int x)
{
return value[x];
}
void SetValue(int x, T v)
{
value[x] = v;
}
private:
T value[];
};
[/source]