C++函数重载无聊2

                  先看一段代码ios

#include <iostream>

using namespace std;


template<typename elemType, size_t nSize>
class CRefAsParam

{
public:
    typedef elemType MyArray[nSize];
    static void RefAsParam(int p[]) {
       

    }
    static void RefAsParam(MyArray & aRR) {
        
    }
};

int main()

{
    typedef CRefAsParam<int, 10> MyType;
    MyType::MyArray a = {20, 30, 77};
    MyType::RefAsParam(a);
    return 0;
}
编译就不能经过

编译出错:spa

/home/zhou/C++/Re/main.cpp:36: 错误:call of overloaded 'RefAsParam(CRefAsParam<int, 10u>::MyArray)' is ambiguouscode

ambiguous:adj. 模糊不清的;引发歧义的编译器

在看编译器的认识it

../Re/main.cpp:16:17: note: static void CRefAsParam<elemType, nSize>::RefAsParam(int*) [with elemType = int, unsigned int nSize = 10u]io

../Re/main.cpp:21:17: note: static void CRefAsParam<elemType, nSize>::RefAsParam(elemType (&)[nSize]) [with elemType = int, unsigned int nSize = 10u, CRefAsParam<elemType, nSize>::MyArray = int [10]]编译

重载是在编译期完成的(多态是在运行期完成的),编译时,选择时不能决定,因此报错。class

相关文章
相关标签/搜索