Say I have a templated class like
template <typename T> struct Node
{
// general method split
void split()
{
// ... actual code here (not empty)
}
};
Need to specialise this in the Triangle class case.. something like
template <>
struct Node <Triangle*>
{
// specialise the split method
void split() {}
} ;
but I don’t want to rewrite the entire template over again! The only thing that needs to change is the split() method, nothing more.
You can provide a specialization for only that function outside the class declaration.
// prototype of function declared in cpp
void splitIntNode( Node & node );
If
splitIntNodeneeds access to private members, you can just pass those members into the function rather than the whole Node.