#is it possible to create a member of a class with pointers

1 messages · Page 1 of 1 (latest)

soft tide
#

As the title says I am currently trying to figure out how do use pointers to create a member of a class this is mainly me trying to create object spawn code for a game

winter lichenBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

bold tinsel
#

what do you mean by this

#

pointers can't create a member, thats part of the declaration of the type

#

you can make pointers to members though

soft tide
bold tinsel
#

I still don't really know what you mean but I will give some examples anyway

#
class A {
 // ...
};

A* a = /* ... */;  // a pointer to an A
#
class A {
public:
  int i;
};

A a = {1};

int* i_ptr = &a.i;// a pointer to the `i` on `a`
int A::* a_i = &A::i;// a pointer to any `i` member of an A

a.*a_i = /* ... */;// can assign to the `i` inside `a` like this
soft tide
bold tinsel
#

yes

#

but types all happen at compile time

#

c++ is statically typed

#

If you want to copy a value you can do that

#

if you want to make a new value you can do that (but not sure what pointer necessarily have to do with that)

soft tide
#

Got it

#

!solved