相关疑难解决方法(0)

为什么这段代码在vs2005中调用不同的模板函数?

代码是:

#include <iostream>
using namespace std;

// compares two objects
template <typename T> void compare(const T&, const T&){
    cout<<"T"<<endl;
};
// compares elements in two sequences
template <class U, class V> void compare(U, U, V){
    cout<<"UV"<<endl;
};
// plain functions to handle C-style character strings
void compare(const char*, const char*){
    cout<<"ordinary"<<endl;
};

int main() {

    cout<<"-------------------------char* --------------------------"<< endl;

    char* c="a";
    char* d="b";
    compare(c,d);

cout<<"------------------------- char [2]---------------------------"<< endl;

    char e[]= "a";
    char f[]="b";
    compare(e,f);

    system("pause");
}
Run Code Online (Sandbox Code Playgroud)

结果是:

------------------------- char*----------------------- ---

Ť …

c++

5
推荐指数
1
解决办法
154
查看次数

标签 统计

c++ ×1