tags:

views:

47

answers:

2

Within my C++/QtTestLib Class, how can I get a count of the number of private functions in this class so that I can output it at runtime?

A: 

ASAIK in C++ this is not possible without third-party parser.

noisy
He's asking about Qt so this is possible because of Qt's metaobject system.
teukkam
yep. Qt implements "reflection" using its metaobject system. pretty cool...
Here Be Wolves
+1  A: 

Something like this? (Not tested)

QObject obj ();
QMetaObject metaobject = obj.MetaObject();
int num_methods = metaobject.methodCount();
int private_methods = 0;
for (int i=0; i<num_methods; i++) {
  if (metaobject.method(i).access() == QMetaMethod::Private)
     private_methods++;
}

where instead of just QObject you have the class that you need to examine.

teukkam
incredible, this might just workout perfect, thanks alot!