Solved

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

Posted on 2010-09-10
12
819 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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
>>  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
Comment Utility
>>struct foo { struct bar {}; };
is this function???
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Expert Comment

by:XMarshall10
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

771 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

7 Experts available now in Live!

Get 1:1 Help Now