Код: Выделить всё
// foo.cpp
const char* foo(bool) { return "bool"; }
const char* foo(int) { return "int"; }
Код: Выделить всё
// main.cpp
const char* foo(bool);
const char* foo(int);
int main()
{
std::cout
Если я объявляю только перегрузку, которую я использую, будет выглядеть так: < /p>
// main.cpp
const char* foo(bool);
int main()
{
std::cout
// main.cpp
// no const char* foo(bool) declaration
const char* foo(int);
int main()
{
// This calls `foo(int) overload
// But would have called `foo(bool)`
// if all the declarations would have been visible
std::cout
// foo.h
const char* foo(bool);
inline const char* foo(int) { return "int"; }
// foo.h will be included in other TUs
< /code>
// foo.cpp
const char* foo(bool) { return "bool"; }
< /code>
// main.cpp
const char* foo(bool);
int main()
{
std::cout
// foo.cpp
const char* foo(int) { return "int"; }
< /code>
// main.cpp
const char* foo(int);
int main()
{
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79769322/is-it-legal-to-forward-declare-just-some-but-not-all-of-the-overloads[/url]
Мобильная версия