I've been playing around with Moose, getting a feel for it. I'd like an example of pure virtual functions like in C++ but in Moose parlance (specifically in a C++-looking way). I know that even with Moose imposing a stricter model than normal Perl, there's still more than one way to do what I'm asking (via method modifiers or SUPER::
calls). That is why I'm asking specifically for an implementation resembling C++ as much as possible. As for the "why?" of this restriction? Mostly curiosity, but also planning to port some C++ code to Perl with Moose in a way that C++-centric people could mostly identify with.
相关问题
- how to define constructor for Python's new Nam
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Keeping track of variable instances
- Why does const allow implicit conversion of refere
相关文章
- 接口B继承接口A,但是又不添加新的方法。这样有什么意义吗?
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
I can think of this way using roles instead of subclassing:
This will give a compilation error because Real doesn't have stuff defined.
Adding stuff method to Real will now make it work:
You might also want to take a look at Jesse Luehrs' MooseX::ABC. It seems very similar to some of the implementations here. From the synopsis:
I know that Jesse is a C++ programmer during the day.
Here is was my attempt (without Roles, for information on Roles see the other answers):
It appears I can't do exactly what I want with Moose, but I can come very close with Roles. Here is the information from the Moose manual entry for Roles: