我想在我的代碼使用模板與矢量大致如下方式:矢量模板 - 「敵不過呼叫」錯誤
在我的頭文件:
template <typename V>
void changeConfig(char option, vector <V> & arg_in){
// ....
}
在源文件中:
vector <int> p = {4};
changeConfig('w' ,p);
這是我得到的錯誤:
/include/config.h:在成員函數「void Cfconfi克:: changeConfig(炭,性病::矢量< _RealType> &)[以V = INT]':
SRC/config_test.cpp:10:38:從實例化這裏
/包括/配置。 H:68:25:錯誤:不對應的調用 '(INT_VECTOR {又名的std ::向量})(標準::矢量&)'
化妝:*** [featureconfig_test.o_dbg]錯誤1
我試過這個線程的建議,但沒有一個似乎工作。
C++ Templates Error: no matching function for call
任何幫助,將不勝感激。謝謝。
好的,我由我的代碼一小段賦予相同的錯誤:
#include <iostream>
#include <stdio.h>
#include <stdarg.h>
#include <cstdio>
#include <opencv2/opencv.hpp>
#include <string.h>
#include <math.h>
#include <complex.h>
#include <dirent.h>
#include <fstream>
#include <typeinfo>
#include <unistd.h>
#include <stdlib.h>
#include <algorithm>
#include <array>
#include <initializer_list>
#include <vector>
#include <algorithm>
using namespace std;
template <typename V>
void changeConfig(char option, vector <V> & arg_in){
vector<int> window = {5};
vector<double> scale = {3};
switch(option){
case 'w':
window(arg_in);
break;
case 's':
scale(arg_in);
break;
}
}
int main(){
vector <int> p = {3};
changeConfig<int>('w', p);
return 0;
}
我使用編譯: 克++ -std =的C++ 0x test_template.cpp -o測試
這給了我此錯誤:
test_template.cpp:在函數「void changeConfig(炭,性病::矢量< _RealType> &)[瓦特第i V = INT] ':
test_template.cpp:45:33:從這裏實例
test_template.cpp:32:33:錯誤:不對應的調用'(標準::矢量)(STD ::矢量&)」
test_template.cpp:35:33:錯誤:不對應的調用 '(標準::矢量)(標準::矢量&)'
您使用哪種編譯器和版本?這編譯好gcc 4.6。 – mfontanini
更新您的編譯器:http://ideone.com/tBsACf – mfontanini
gcc版本4.6。3(Ubuntu/Linaro 4.6.3-1ubuntu5) – mystique