member variable ptr cast

N

Noah Roberts

Consider the following hierarchy:

struct record
{
};

struct test_record
{
};

struct an_object
{
test_record r;
};

I want a member pointer variable to r but I want it to be cast as a
record. Is this possible? I tried the following:

static_cast<record an_object::*>(&an_object::r);

No worky.
 
N

Noah Roberts

Victor said:
'an_object' does not have a member of type 'record'.

Now, answer my question: What do you think you need that for?

test_record was supposed to be a sub of record. My mistake.
 
N

Noah Roberts

Consider the following hierarchy:

struct record
{
};

struct test_record : record
{
};

struct an_object
{
test_record r;
};

I want a member pointer variable to r but I want it to be cast as a
record. Is this possible? I tried the following:

static_cast<record an_object::*>(&an_object::r);

No worky.
 
N

Noah Roberts

Victor said:
I still think it's not possible.

Well, I can't think of a way either.
You still haven't answered my question: why do you think you need that?

You're being kinda demanding, don't you think? Not exactly necessary
information to answer the question asked. I think I need it because
I've yet to come up with an alternative solution to the problem I'm
facing of course.
 
N

Noah Roberts

Victor said:
Hell, if you don't need help, maybe you should just go solve your
problems by yourself, don't you think?

I asked a pretty direct question about what I needed to know. You did
the best you could with that question. Thank you. That's all I want to
know...don't need help doing my job.

I asked because I think that
while you're explaining you might have a revelation or somethin' or
maybe somebody here will give you an alternative to your alternative. A
pointer to member is a rarely needed thing. Have you tried a regular
pointer instead?

Obviously there are some pretty important differences between member
pointer and pointer such that they are not at all interchangeable concepts.
 

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

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,458
Latest member
Chris#

Latest Threads

Top