explicit
keywordfoo.c
as below:
#include <stdio.h> void foo(void) { printf("This is foo!\n"); }
foo.c
to its object code:
$ gcc -c foo.c
main.cc
, in which
foo()
is called.
void foo(void); int main(void) { foo(); return (0); }
main.cc
to its object code:
$ g++ -c main.c
main.o
and foo.o
to its
executable main
:
$ g++ main.o foo.o -o main
nm
to look at main.o
and foo.o
.
min.cc
as below:
template<class T> const T &min(const T &a, const T &b) { return (a < b ? a : b); } int main(void) { min(1, 2); min(1.0, 2.0); min('1', '2'); return (0); }
min.cc
and use nm
to find out
how many min()
functions are created in the
executable.
$ g++ min.cc -o min $ nm min
explicit
keyword
explicit.cc
as below:
#include <stdio.h> class String { public: String(int n) { printf("A\n"); } String(const char *s) { printf("B\n"); } }; int main(void) { String s = 'a'; // implicit conversion for single argument constructor }
$ g++ explicit.cc -o explicit $ explicit
explicit
in front of the first constructor,
recompile again and see what happens.