template<class T, int Num>
struct Test
{
int Method() const {
return 2;
}
};
template<int Num>
struct Test<int, Num>
{
int Method() const {
return 42;
}
};
#include <iostream>
int main() {
std::cout<<Test<int, 4>().Method()<<std::endl;
std::cout<<Test<float, 4>().Method()<<std::endl;
}
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
But if i have 100 other methods which will not need changing, do i need to copypasta those too? Or just the stuff that needs specialization?
The former.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
There are hacks to get around needing to redefine every member function. For example, you can put all the functions that don't need changing in a base class and create a derived class just for the functions that need specialization.