the_candyman
the_candyman

Reputation: 1663

How to know if function in c++ are unused if they are in a class?

Is there a method to know if a private function isn't used within the definition class? Also, I need to know if there some public function of the class which is not used outside the class. How can achieve this?

Upvotes: 0

Views: 233

Answers (2)

Sjoerd
Sjoerd

Reputation: 6875

Remove the function and see whether your project still compiles and links.

You should remove the definition (in the cpp file) only, and leave the declaration in the header. Otherwise overload resolution could mask the places where your function is called.

Upvotes: 1

Yeraze
Yeraze

Reputation: 3289

The solution depends heavily on the situation.

In many cases, you can simply grep or ag the source for calls to the function. Also, there are tools like cppcheck that can analyze a source base and tell you this.

However, if you don't have source then there are other methods.

Add code to the functions that will output somehow visibly (perhaps to a logfile) when called. This is what gcc's Code Coverage functions do.

Upvotes: 2

Related Questions