Solved

C++/QtTestLib  programatically get number of functions in class

Posted on 2010-09-10
12
821 Views
Last Modified: 2013-11-23
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?
0
Comment
Question by:NewtonianB
  • 4
  • 2
  • 2
  • +2
12 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 33647806
C++ has RTTI (Run-Time Type Information) for that (http://en.wikibooks.org/wiki/C++_Programming/RTTI), yet that does not account for the number of member functions. So I'd say this is impossible, unless you ask the user to count them. BTW, you might want to check out Doxygen (http://www.stack.nl/~dimitri/doxygen/) which allows to analyze source code.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 33647989
>> I'd say this is impossible
Concur, since C++ doens't support runtime reflection there is no way to do this.
0
 
LVL 7

Expert Comment

by:irfan_omair
ID: 33649409
Only One way I  can think of to open your c++ class header file where class is declared and read the source file as text and after "private" check how many braces ;(); are there that will indicate it is function and you keep counter for that.
but you will have to check other condition too like if you encounter "public' you will have to skip the count as well if you dont find any key word you will have to take that in count etc etc , it little complex i can understand but that is only way I  can think of
0
 
LVL 40

Expert Comment

by:evilrix
ID: 33649619
>>  check how many braces ;(); are there that will indicate it is functionOr anything else nested that uses braces!struct foo { struct bar {}; };Unfortunately the grammar for C++ makes this a non-trivial task!http://www.externsoft.ch/download/cpp-iso.html
0
 
LVL 7

Expert Comment

by:irfan_omair
ID: 33649812
>>struct foo { struct bar {}; };
is this function???
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:XMarshall10
ID: 33660336
In general, in all the c++ header files, you won't find the term "private:" explicitly mentioned. As in C++, when no class access specifiers are present, the following code is considered to be private.

So you have to keep that in mind also, if you are planning to parse your header files for a list of its private functions.

--XM
0
 
LVL 40

Expert Comment

by:evilrix
ID: 33660429
>> is this function???

No, I am pointing out that there are other things in a class that use braces other than functions to you can't just "check how many braces". Check my previous comment again, "Or anything else nested that uses braces!".

>> In general, in all the c++ header files, you won't find the term "private:" explicitly mentioned
Why won't you? That's a but of an unfounded presumption. I always explicitly define private areas... in fact I have multiple private areas for different things.

>> As in C++, when no class access specifiers are present, the following code is considered to be private.
That doesn't mean private sections wont' be declared.
0
 
LVL 1

Expert Comment

by:XMarshall10
ID: 33660506
evilrix:

I have come across many source codes where private sections have not been explicitly defined by the programmer, in the class declaration.

That's what I meant in my earlier post.

Alas , we don't live in a perfect world. (-:

--XM
0
 
LVL 40

Expert Comment

by:evilrix
ID: 33660515
>> Alas , we don't live in a perfect world.
Indeed, hence my observation that you cannot make a generalisation about this.
0
 

Accepted Solution

by:
NewtonianB earned 0 total points
ID: 33679037
Guys thanks for input, I found solution, we can't do in C++ but this is QT/C++ so if the class is derived from a QtObject I can use qtmetaobject functions to loop through function in class! pretty awesome
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now