#about the class/struct member variable and function

17 messages · Page 1 of 1 (latest)

pastel grove
#

so if I have a pointer or a normal variable and a function inside of a class or struct, how does class/struct knows which member var/function is inside of it?

tardy flaxBOT
#

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.

pastel grove
#

the pointer, var and function is stored like other normal stuff outside of the class right? or am I wrong. if yes how does when u make an obj of that class, it knows which one is inside of which

sharp pumice
#

The class definition.

pastel grove
#

no i want to know how that work

#

@sharp pumice

sharp pumice
#

The compiler reads that and knows.

pastel grove
#

bruh

#

i want to know it a bit deeper

uncut kraken
#

there's no deeper

#

you write code that respect the rules of the language, the compiler sees that and knows what members are in any valid type

#

if you're asking about how a compiler can be implemented to do that, that's literally up to the implementation of the compiler

#

how does class/struct knows which member var/function is inside of it?
...
how does when u make an obj of that class, it knows which one is inside of which
that's up to internal compiler implementation, so there's nothing to say about it in general aside from "the compiler must know"

because reflection isn't a thing, there isn't even a context where that piece of information (all the members in a class) is relevant from a purely language point of view; the closest thing to it is when you try to use a member, so when you write stuff like object.data_member or object.member_function(arguments)
if you include static member, you also need to deal with syntax like T::member
and the short of it, from a language point of view, is that you have to understand the rules of "name lookup", and maybe "overload resolution"

#

if you actually meant to ask about a potential compiler implementation, then arguably go look at an implementation

#

I guess I have one more random remark

#

If your question is more about "how can a compiler interpret a class definition to know what members exist, then buildup whatever internal representation of the class", then that topic relates to "language theory" and formal grammar and how you can implement a parser for that language/grammar

pastel grove
#

not what i mean sadly