Reputation: 11
Suppose I have inheritance like below:
class A
{
public:
A(){}
int s;
void Show(){}
};
class B : public A
{
public:
B(){}
int y;
void MyShow() {}
};
int main()
{
B b;
}
Is there a way that I can know by any mechanism [runtime/debug] etc what are the member variables / methods of object b
- I mean complete list along with all it inherited?
Upvotes: 1
Views: 767
Reputation: 35795
You can use ptype
gdb command. However it will not print members of inherited type, you will have to do it yourself. Here you can print type B
, note that it is inherited from type A
and print A
as well:
(gdb) ptype B
type = class B : public A {
public:
int y;
B(void);
void MyShow(void);
}
(gdb) ptype A
type = class A {
public:
int s;
A(void);
void Show(void);
}
(gdb)
Upvotes: 0
Reputation: 31459
You cannot do that. C++ does not support reflection (the feature you'd need to be able to do this). You cannot iterate through an object and discover its members like in some other (dynamic) languages.
Upvotes: 1