Portál AbcLinuxu, 26. října 2025 23:27
$ cat implicit.cc
#include <iostream>
int f(int a, int = 2, int c = 3);
int f(int a, int b, int c)
{
std::cout << a << " " << b << " " << c << std::endl;
return 0;
}
int main(void)
{
f(1);
f(2, 3);
f(3, 4, 5);
}
$ g++32 -Wall implicit.cc ; ./a.out
1 2 3
2 3 3
3 4 5
$ g++32 --version
g++32 (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-47.fc4)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$
#include <iostream>
void f1( int, ... )
{
std::cout << "f( int, ... )\n";
}
void f2( int, int = 0 )
{
std::cout << "f( int, 0 )\n";
}
int main()
{
f1( 1 );
f2( 1, 2 );
return 0;
}
Pokud se budou jmenovat stejne, napr. "f":
elviin@nilix>g++ test.cpp </tmp test.cpp: In function `int main()': test.cpp:17: error: call of overloaded `f(int)' is ambiguous test.cpp:4: error: candidates are: void f(int, ...) test.cpp:10: error: void f(int, int)... ale to je jina kapitola.
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.