On 12/09/2012 11:52 AM, js.mdnq wrote:

> Well, I would not say they are exactly the same.

Do they have to be exactly the same? You are showing a method that fails to satisfy a requirement, I show another method which according to fail to satisfy another requirement. Software is engineering as well. What is the problem? Let's just solve it.

> In your case you are
> aliasing on opGet while I'm talking about aliasing on the struct itself.

I know.

> e.g., there might be other members you do want the user to have access
> too.

Then I give access to those members.

> With your's, they won't be able to access them(your's is actually
> more restrictive).

I don't see that.

> For example, how can they access a "Validate" method like I have using
> your struct?

It is so trivial that I am beginning to think I have not understood a tiny bit of what you have been saying, but here it goes: :)

struct sPassword
{
private:
    string Password_;

public:

    alias opGet this;

    void opAssign(string value)
    {
        Password_ = value;
    }

    string opGet() { return "******"; }

    bool Validate(string pass) { return pass == Password_; }
}

void main()
{
    sPassword myPass;
    myPass = "hello";
    assert(myPass == "******");
    assert(myPass.Validate("hello"));    // <-- here
}

I hope others can show me what I've been misunderstanding. :-/

Ali

Reply via email to