Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-09-10
12
Medium Priority
?
829 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 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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. …
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

721 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