Search ProofOfProgress Blog

Monday, February 29, 2016

Enforce classes have same static method c++

All my classes must have a method called unitTest in DEBUG mode. This is because I don't want my test code in a separate library.

Separation of concerns is nice and all. But I think that separation also makes it more likely that your test library code will decay.

This might be what I need:

Basically, extend from a header-only class that defines no implementation. And have the function within that class be templated.

Something like:

template< typename T>
    static double foo( vector arr );

In the header, without any implementation.

Can you extend from a class with no implementation? I bet you can. Need to look into that.

Maybe I need a "pure virtual function"?

But that specifies type... Do I need a "pure virtual template function"? That sounds fancy and over complicated.

Yes, you can.

No comments:

Post a Comment