Jump to content
  • Advertisement
Sign in to follow this  
noatom

c++ pointer to member array of int

This topic is 1934 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

No,i mean with the special syntax for pointer to member,like:

 

x d

x* z = &d;

int x::*mypointer = &x::arr;

 

the above would work if arr would be a simple int,not an array

Share this post


Link to post
Share on other sites
This is the hardest part of C++ to me and why I have had so much trouble with it. There are 3 answers to this question and all three show a different way, pointers can just be too confusing.

Share this post


Link to post
Share on other sites

Yes, pointers can be confusing. But there was only one answer to this question, not three. My first response, for example, was not the kind of pointer he was looking for and thus is not an answer. Member pointers are different from pointers. My second response is the only answer in this case if he wants a member pointer to an array of 10 integers.

Edited by Brother Bob

Share this post


Link to post
Share on other sites

Also, if the wrap around syntax of array types is confusing, you can use a typedef to define the pointer type in parts:

typedef int IntArray10[10];
IntArray10 x::*mypointer = &x::arr;

Share this post


Link to post
Share on other sites

@LordRhys,don't worry,I've seen a lot of code but I never actually enocuntered those pointers.I asked because I had an exercise about them.You can always make a simple pointer and point it at the array.

 

Even though you won't see many things used in c++,it's good to have an ideea about them,because you might encounter them once.

Share this post


Link to post
Share on other sites

I've used pointer to member functions but not pointer to member variables. It's pretty rare.

 

Basically it's just an offset and may be useful if you want to point to one of several arrays in an object... Still pretty much a borderline case though...

 

I'm not even sure if the syntax is any better than the (unsafe) C way of just calculating the offset. I supose it's safer but if I was doing anything like that it would be low level and wrapped in a class anyway...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!