Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If the compiler does global optimizations, it can infer when virtual functions aren't really virtual. For example, if a virtual function is never overridden, or never overridden by any live type (after dead code removal), then it can be implicitly converted to a non-virtual function.

Since C++ doesn't have interfaces, only pure virtual functions, you'll pay the cost of the virtual dispatch, even if you use delegation, won't you? (The context of my comment is the use of interfaces, with implementations using delegation instead to do implementation inheritance)

e.g.

interface I

class Concrete implements I

  delegate to Shared
class Concrete2 implements I

  delegate to Shared

Yes, if you don't use any interfaces at all, and just a concrete class, then it's a different situation.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: