Function Overloading #20884

Open
opened 2026-01-31 07:26:48 +00:00 by claunia · 0 comments
Owner

Originally created by @shiyou-t1c on GitHub (Nov 24, 2023).

Windows Terminal version

No response

Windows build number

No response

Other Software

No response

Steps to reproduce

#include <iostream>
int c(const char (&a1)[3])
{
	return 1;
}
int c(const char *a1)
{
	return 3;
}
int main()
{
	char arr[] = "hi";
	std::cout << c(arr) << std::endl;
	return 0;
}

Expected Behavior

No response

Actual Behavior

https://learn.microsoft.com/en-us/cpp/cpp/function-overloading?view=msvc-170

int c(const char (&a1)[3]);           char[3]          const char [3]           const char (&)[3]

int c(const char *a1);                char[3]          char*                         const char*

I don't understand why int c(const char (&a1)[3]); Matching has a higher priority.Sequences of trivial conversions are classified as exact matches.I really don't understand.How to match the priorities after many conversions?

Originally created by @shiyou-t1c on GitHub (Nov 24, 2023). ### Windows Terminal version _No response_ ### Windows build number _No response_ ### Other Software _No response_ ### Steps to reproduce ```c++ #include <iostream> int c(const char (&a1)[3]) { return 1; } int c(const char *a1) { return 3; } int main() { char arr[] = "hi"; std::cout << c(arr) << std::endl; return 0; } ``` ### Expected Behavior _No response_ ### Actual Behavior [https://learn.microsoft.com/en-us/cpp/cpp/function-overloading?view=msvc-170](url) ```c++ int c(const char (&a1)[3]); char[3] const char [3] const char (&)[3] int c(const char *a1); char[3] char* const char* ``` ### **I don't understand why int c(const char (&a1)[3]); Matching has a higher priority.Sequences of trivial conversions are classified as exact matches.I really don't understand.How to match the priorities after many conversions?**
claunia added the Needs-TriageIssue-Bug labels 2026-01-31 07:26:48 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20884