Member offset pointers ?

A

Adam Benson

Hi,

In C++ you could define a member offset pointer which worked on any instance
of a class.

i.e.
class MyClass
{
int IntOne;
int IntTwo;

void SetInt(int MyClass::* p)
{
this->*p = 100;
}
}

void Eg()
{
MyClass c;

// Sets c.IntOne
c.SetInt(&MyClass::IntOne);
// Sets c.IntTwo
c.SetInt(&MyClass::IntTwo);
}

A rather simplistic illustration, and my apologies if the syntax isn't
exactly right - I haven't worked with C++ for a couple of years. Is there
anything like this in C# ? I've searched and can't find it.

Thanks,

Adam.

--

- Adam.

==============================
(e-mail address removed)
 
G

Guest

you can pass things by reference using the ref keyword. This enables you to
pass a member variable to a function and have that function update the member
variable.
e.g

void SetInt(ref int p)
{
p = 100;
}


HTH


Ciaran O'Donnell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top