C ++ - what is an operator. *?

In C ++ you cannot overload a statement .*

Can someone give me an example of using a statement .*?

+3
source share
5 answers
+8
source

:

class Action
{
    public:
        void yes(std::string const& q) { std::cout << q << " YES\n"; }
        void no(std::string const& q)  { std::cout << q << " NO\n"; }
};

int main(int argc, char* argv[])
{
    typedef void (Action::*ActionMethod)(std::string const&);
                       //  ^^^^^^^^^^^^  The name created by the typedef
                       // Its a pointer to a method on `Action` that returns void
                       // and takes a one parameter; a string by const reference.

    ActionMethod method = (argc > 2) ? &Action::yes : &Action::no;
    Action  action;

    (action.*method)("Are there 2 or more parameters?");
     //  ^^^^^^ Here is the usage.
     //  Calling a method specified by the variable `method`
     // which points at a method from Action (see the typedef above)
}

. , .: -)

+3

, -. . .

+2

. * . , , , , . . * .

+2
source

All Articles