D
D
Daniil Demidko2016-03-03 01:37:45
C++ / C#
Daniil Demidko, 2016-03-03 01:37:45

Function links?

Here is the function:
void func () ;
Please explain the difference between this
void ( * const pointFunc ) () = func ;
AND this: I
void ( & refFunc ) () = func ;
didn’t find anything for the last option, Stroustrup doesn’t have it either, and only options with a function pointer are googled.
I know about function pointers, but references to them are something new.
This option compiles for me even with -c++ 98, then why there are no examples of its use anywhere, it’s more convenient because instead of a constant pointer.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2016-03-03
@Daniro_San

why there are no examples of its use anywhere, it is more convenient instead of a constant pointer.

What is more convenient? The link must be initialized at the time of creation and cannot be changed later. A function in C++ cannot be created or returned from a function, why a reference?

A
AtomKrieg, 2016-03-03
@AtomKrieg

Internal links are pointers, so they can often be used for the same purpose. They are safer and more convenient, but there are limitations. The compiler imposes restrictions.

int a= 10;
int& b = a; //int *b = &a;
b = 5;      //*b = 5; 

cout << a << endl;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question