emplicitly and explicitly function declaration

Can anyone please tell me what is the difference between declaring a function explicitly and implicitly ?
explicit is used for constructors to signify that it won't automatically make the conversion to the class type, ie you have to explicitly use the constructor
and what is implicit function declaration ?
what is the difference between declaring a function explicitly and implicitly?


Functions can only be declared explicitly.

So says the standard.

So say we all.

The keyword "explicit" has nothing to do with explicit function declarations.
From http://en.wikipedia.org/wiki/Compatibility_of_C_and_C%2B%2B :
implicit function declarations (using functions that have not been declared) are not allowed in C++
An implicit function is one where the compiler assumes that the function is declared&defined elsewhere. That is, the compiler doesn't know anything more about the function than what it can figure out when you call it.
1
2
3
4
5
int main()
  {
  printf( "Hello world!\n" );  /* printf() !!?? what's that? */
  return 0;
  }

In the example, since printf() was never declared, the compiler had to try to figure out what kind of function it is. It looks like

void printf( const char* );

We know different, but that is close enough so it works. (Usually. A C program is automatically linked with the actual printf() function.)

Now, if we want to fix the above, we can declare the function properly -- that is, explicitly:
1
2
3
4
5
6
7
int printf( const char*, ... );  /* here the function is explicitly declared */

int main()
  {
  printf( "Hello world!\n" );  /* now it can be used, since the compiler knows about it */
  return 0;
  }

Keep in mind that the function must still be defined somewhere. In the case of printf() it is defined in the standard library that is automatically linked with your C program. For functions you create yourself you must also declare them:
1
2
3
4
5
6
7
8
9
10
11
12
void print_sum( int a, int b );  /* explicit declaration */

int main()
  {
  print_sum( 27, 15 );  /* happy compiler */
  return 0;
  }

void print_sum( int a, int b )  /* definition */
  {
  printf( "%d + %d = %d\n", a, b, a + b );  /* implicit function use */
  }


Hope this helps.
So you mean if a function is used withour declaring it , It will be implicit function .

If a function is declared and then used somewhere in the program it will be explicitly.
Last edited on
Yep. :-)
Thanks Duoas !
Last edited on
Topic archived. No new replies allowed.