I don't know how commonly it is used, but it certainly is commonly understood. For example, a person may have two roles within a company. In certain situations, he might take off one hat and put on another. That means he changes roles. (He might not actually be wearing a hat.)
As far as I know, the expression is always stated in the second person: "You can't have your cake and eat it too." The "you" in that sentence is not directed to anybody in particular.