llamar a una función global con un método de clase con la misma declaración
Me gustaría envolver una biblioteca de C dentro de una clase de C++. Para mi clase de C++ también me gustaría tener la misma declaración utilizada por estas funciones de C: ¿es posible hacer eso?
Si por ejemplo tengo el caso a continuación, ¿cómo sería posible distinguir la función C de la función C++? Me gustaría llamar a la C fuera de curso.
extern int my_foo( int val ); //
class MyClass{
public:
int my_foo( int val ){
// what to write here to use
// the C functions?
// If I call my_foo(val) it will call
// the class function not the global one
}
}
28
3 answers
Utilice el operador de resolución de alcance ::
:
int my_foo( int val ){
// Call the global function 'my_foo'
return ::my_foo(val);
}
48
Author: Adam Rosenfield,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-08-22 15:46:02
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-08-22 15:46:02
::my_foo(val);
Eso debería bastar.
5
Author: nobody,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-08-22 15:39:01
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-08-22 15:39:01
Use Búsqueda de nombres calificados
::my_foo(val);
Esto le indica al compilador que desea llamar a la función global y no a la función local.
5
Author: Alok Save,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-08-22 15:42:43
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-08-22 15:42:43