By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,143 Members | 865 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,143 IT Pros & Developers. It's quick & easy.

Member offset pointers ?

P: n/a
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.

==============================
Ad*********@Omnibus.NOSPAMMYSPAMSPAM.co.uk
Sep 22 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

"Adam Benson" wrote:
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.

==============================
Ad*********@Omnibus.NOSPAMMYSPAMSPAM.co.uk
Sep 22 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.