void f1(int (&)[8])
{}
void f2(int (&)[])
{}
int main()
{
int a[8];
f1(a); // OK
f2(/* What should I put here? */); // ???
return 0;
}
How do I call f2?
PS: void f2(int (&)[]) {} is legal under VC++ 2012.
consider the following:
template<class T>
struct A
{};
template<class T>
struct A<T[]>
{};
template<class T, size_t size>
struct A<T[size]>
{};
C++ has an explicit rule that disallows references or pointers to arrays without bounds as parameters (but those are otherwise valid types). The following would be a valid argument to such a parameter
extern int arg[];
Note that you cannot use an array with a size. C++ does not have the type compatibility concept. C has, and makes an array type without size compatible to the corresponding array type with a size. In C++, the typesystem is stricter, types have linkage and prototypeless function types do not exist, so type compatibility is not a real need, so C++ dropped it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With