Solved

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

Posted on 2010-09-10
12
825 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert MFC APP to Win32 APP. 19 94
Installshield for Embarcadero EX 10.1 Berlin 4 60
DCT of  2D array using fftw in c++ 9 66
No module found pypyodbc, 3 32
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. …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

860 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