Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (50.2k points)
recategorized by
As you know that in Python, we have one function named dir() that will list all the attributes/functions/members of an object. Is there an approach for C++ objects to get all the members, either in gdb or some other service?

1 Answer

0 votes
by (108k points)
edited by

Kindly be informed that in C++, we do not have a built-in mechanism for obtaining this. 

The gdb can only be able to give you the data fragments for your object, but you need to have an instance of the object for reference and do print 'a' if the value of the global variable was a. To find the functions, you have to use info functions A::*, if the class name was A. This will not find inline methods(note baz_inline in the example).

class A {


    void foo ();

    int bar (int);

    void baz_inline () {}

    double d;

    short p;


A a;

void A::foo () {}

int A::bar (int) { return 0; }

int main () {}

$ g++ -g

$ gdb a.out

(gdb) p a

$1 = {d = 0, p = 0}

(gdb) p &a.d

$2 = (double *) 0x600920

(gdb) p &a.p

$3 = (short *) 0x600928

(gdb) info functions A::*

All functions matching regular expression "A::*":


int A::bar(int);

void A::foo();

(gdb) quit

If you want to know more about Python, then do refer to the Python course that will help you out in a better way. 

Related questions

0 votes
1 answer
asked Jul 9, 2019 in Python by ParasSharma1 (19k points)
0 votes
1 answer
+1 vote
1 answer

Browse Categories