Is there any (good) way of having equally named class and global function in the same namespace in C++?
Below code does not compile because it favors function over class name.
void PrintNumber( int val ) { std::cout << "from function: " << val << std::endl; } struct PrintNumber { void operator()( int val ) const { std::cout << "from operator: " << val << std::endl; } }; int main() { auto f1 = std::function<void(int)>( PrintNumber() ) ; // Functor class instance // ERROR occurs here auto f2 = std::function<void(int)>( PrintNumber ) ; // Global function f1( 123 ); f2( 456 ); cin.get(); }
NumberPrinteror similar.PrintNumberisn't a good class name.