On 09.12.2013 00:54, Marcel M�ller wrote:
>
> OK, a compiler could warn about everything it likes. But what could be
> the idea of this warning?
The compiler didn't notice that the address of the private function is
exposed, or else the logic of the warning doesn't include such
considerations at all.
> What is wrong with a class with only private functions?
If that's *all* that the class has, then they're useless baggage.
For such a class a compilation warning would be appropriate.
But in the presented code the class also has a public typedef that
exposes one of the private functions, which presumably is why you
reacted to the warning. ;-)
* * *
Here's a demo of how such a typedef allows a function to be called by
any code, illustrating that in spite of the "private:" the function is
publicly accessible with just a *little* more work than usual:
[code]
template< auto()->int > struct Whatever {};
class Not_quite_useless
{
private:
static auto foo() -> int { return 666; }
public:
typedef Whatever<&foo> Access;
};
//----------------------------------------------
#include <iostream>
using namespace std;
template< auto exposed_func() -> int >
void foo( Whatever<exposed_func> )
{ cout << exposed_func() << endl; }
auto main()
-> int
{ foo( Not_quite_useless::Access() ); }
[/code]
By the way, neither Visual C++ 12.0 nor MinGW g++ 4.7.2 warned about the
Not_quite_useless class above.
Cheers & hth.,
- Alf