wskaźnik do const vs zwykły wskaźnik (dla funkcji)
Czy jest jakaś różnica między wskaźnikiem a stałym i zwykłym wskaźnikiem funkcji? Kiedy odpowiednie jest użycie kwalifikatora const do funkcji samodzielnych?
Napisałem krótką próbkę, aby zilustrować moje pytanie:
#include <iostream>
using namespace std;
int sum( int x, int y ) { return x + y; }
typedef int sum_func( int, int );
int main()
{
const sum_func* sum_func_cptr = ∑ // const function
sum_func* sum_func_ptr = ∑ // non-const function ?
// What is the difference between sum_func_cptr and sum_func_ptr
int x = sum_func_cptr( 2, 2 );
cout << x << endl;
int y = sum_func_ptr( 2, 2 );
cout << y << endl;
sum_func_cptr = 0;
sum_func_ptr = 0;
return 0;
}
g ++ nie daje żadnych ostrzeżeń. Dlatego pytam.