我想寫一個區分數組和指針的函數。這是爲了確定文字字符串的大小而需要的。我試過了:數組指針與數組引用的區別
template<typename Ty>
void f(const Ty* rhs) {
std::cout << __FUNCTION__ << rhs << std::endl;
}
template<typename Ty, size_t Dm>
void f(const Ty(&rhs)[Dm]) {
std::cout << __FUNCTION__ << rhs << std::endl;
}
int main(int, char*[]) {
const char arr0[] = "test2";
const char* ptr = "test3";
const char arr6[6] = "test4";
f("test1");
f(arr0);
f(ptr);
f(arr6);
return 0;
}
但是編譯器(VS2013)告訴我這個調用是不明確的。任何提示?
在此先感謝。
,如果你指定哪個函數調用的不明確這將有助於(我可以猜測,但這些信息應該是這個問題。) – juanchopanza