why there are no multimethods in c++? [closed]

2019-04-19 16:54发布

I read many article about how to implement multimethod in c++:

  1. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1529.html
  2. http://www.codeproject.com/KB/recipes/mmcppfcs.aspx
  3. http://lambda-the-ultimate.org/node/2590
  4. http://parasol.tamu.edu/people/peterp/omm/

why there are no multimethod in c++?

why do not they get supported by c++ standard?

3条回答
戒情不戒烟
2楼-- · 2019-04-19 17:14

Straight from the horse's mouth:

"I rejected multi-methods with regret, because I liked the idea, but couldn't find an acceptable form under which to accept it."

Bjarne Stroustrup, The Design and Evolution of C++ (p297)

And later:

"Multi-methods is one of the interesting what-ifs of C++. Could I have designed and implemented them well enough at the time? [...] What other work might have been left undone to provide the time to design and implement multi-methods?"

(p298f)

In general, whenever you feel the urge to know why some particular C++ feature was implemented, or was not implemented, or was implemented the way it is now, and if that feature pre-dates the standardization, you want to read D&E.

查看更多
叛逆
3楼-- · 2019-04-19 17:14

Just because it could be done doesn't mean it's a problem that it wasn't done. One criticism of C++ is along the lines of "Stroustrup took everything anyone had heard of, and tried to include it."

Plus, as Raymond Chen says, "Every feature starts off with -100 points." That is, before you ask why C++ doesn't have these things, you should explain in detail why it needs them. Otherwise your feature stays in negative territory, due to the costs associated with it.

查看更多
男人必须洒脱
4楼-- · 2019-04-19 17:37

As Bjarne has pointed out a number of times, when people criticize C++, it usually runs something like: "C++ is too big, too complex, has too many features, and it's too hard to learn -- you should really work at making it smaller and simpler. Oh, and while you're working on that I also have this really great idea for a killer feature that you should add!"

查看更多
登录 后发表回答