G
gustavo.scotti
Hi.
What happens if a given template typename T is int& and you need to
reference an int pointer, or even an int?
e.g:
template <typename T>
void do_something( void *ptr, void(*funct)(T arg1)) {
funct( *(T *)ptr);
}
it's ok if you call it
void int_ok( int a);
int global = 123;
do_something( &global, int_ok);
but not ok if you call
void int_not_ok( int& a);
do_something( &global, int_not_ok);
if you don't use the templates, the logic is all ok, because a content
of a pointer can be referenced to a calling function.
by the way, the error caught is that you cannot reference a pointer to
a reference, like *(int& *). To my common sense, this is just like
*(int *).
Is there any obscure method to remove a reference from a template?
What happens if a given template typename T is int& and you need to
reference an int pointer, or even an int?
e.g:
template <typename T>
void do_something( void *ptr, void(*funct)(T arg1)) {
funct( *(T *)ptr);
}
it's ok if you call it
void int_ok( int a);
int global = 123;
do_something( &global, int_ok);
but not ok if you call
void int_not_ok( int& a);
do_something( &global, int_not_ok);
if you don't use the templates, the logic is all ok, because a content
of a pointer can be referenced to a calling function.
by the way, the error caught is that you cannot reference a pointer to
a reference, like *(int& *). To my common sense, this is just like
*(int *).
Is there any obscure method to remove a reference from a template?