Solved

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

Posted on 2010-09-10
12
828 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

636 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