You are not logged in.
hello, here is my code ...
#include <iostream>
using namespace std ;
int funktion_1(int a){
cout << "dies ist funktion1... " << endl ;
return 0 ;
}int funktion_2(int a){
cout << "dies ist funktion2... " << endl ;
return 0 ;
}inline int funktion_3(int a){
cout << "dies ist funktion3... " << endl ;
return 0 ;
}int funktion_4(int a){
cout << "dies ist funktion4... " << endl ;
return 0 ;
}inline int funktion_5(int a){
cout << "dies ist funktion5... " << endl ;
return 0 ;
}int main(){
// Jetzt kommen "inline"-Funktionen ...
int a ;int *main_inline(a) = &main(a) ;
int *funktion1_not_inline() ;
int *funktion2_not_inline() ;
int *funktion3_inline() ;
int *funktion4_not_inline() ;
int *funktion5_inline() ;
cout << "die main-funktion hat die adresse... " << main_inline << endl ;
cout << "die funktion1, nicht inline, hat die adresse... " << funktion1_not_inline << endl ;
cout << "die funktion2, nicht inline, hat die adresse... " << funktion2_not_inline << endl ;
cout << "die funktion3, inline, hat die adresse... " << funktion3_inline << endl ;
cout << "die funktion4, nicht inline, hat die adresse... " << funktion4_not_inline << endl ;
cout << "die funktion5, inline, hat die adresse... " << funktion5_inline << endl ;
return 0 ;
}
i want to build pointers to look at the function-adresses... i also want a pointer to main-function ... then i want to let read out the adresses... i also want to test the inline-command... 1 function is inline ...
what should i change to make that code runnable ?
and: can i do something similar with references(&) instead of pointers(*)?
Last edited by lo7777799 (2025-06-15 17:52:20)
Offline
Hi,
In order to declare a pointer to a function in C++ you would have to use the following syntax:
return_type (*pointer)(arg_types);
e.g. int (*funktion1_not_inline)(int);
So for example with your main_inline pointer
int (*main_inline)();
And then initialise it with
main_inline = main;
Which can therefore be combined into:
int (*main_inline)() {main};
This would then apply to all the other functions respectively
Lastly, to print the address
std::cout << &main_inline;
Last edited by airbus777neo (2025-06-16 19:05:44)
Just a computer fanatic finally beginning to etch out of his shell in experience
"The man who chases two rabbits catches none." — Confucius
Offline
hello, here is my code ...
This code is not valid C++ code.
int *funktion1_not_inline();
This declares a function which returns pointer to int. However, you already have defined function with the same name which returns int.
If you want to declare a pointer to a function which returns int, you can write
int (*p)(); // uninitialized pointer
int (*p1)() = funktion1_not_inline; // initialized pointer
// or
int (*p2)() { funktion2_not_inline }; // initialized pointer
i want to build pointers to look at the function-adresses...
See notes on std::basic_ostream<CharT,Traits>::operator<<
There are no overloads for pointers to non-static members, pointers to volatiles,(until C++23) or function pointers (other than the ones with signatures accepted by the (18-20) overloads).
· Attempting to output such objects invokes implicit conversion to bool, and, for any non-null pointer value, the value 1 is printed (unless boolalpha was set, in which case true is printed).
i also want a pointer to main-function ... then i want to let read out the adresses... i also want to test the inline-command... 1 function is inline ...
Why do you need this? What is your goal?
Offline