
29 Apr
2010
29 Apr
'10
9:34 a.m.
Making it private don't see how it could work C++'s private does not prevent ovrerriding (unlike some other languages)
Why should the virtual function be private? The desired interface is a function that takes any type the implements the random double generator 'concept'. Template functions cannot be virtual. That leads to a private virtual function (which can be overridden in derived classes, but not called) and a public template function that calls the private virtual function after translating the argument into a useable form.
More generally, Herb Sutter's recommendation to "prefer to make base class virtual functions private" (http://www.gotw.ca/publications/mill18.htm) is sound advice.