我想編譯一個我編寫自己的C++程序。而且我在編譯時遇到了麻煩。C++編譯錯誤:'<'令牌之前的預期初始化器
的quicksort.hpp文件是:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include "cv.h"
#include "cv.hpp"
#include "highgui.h"
void print<CvPoint3D32f>(vector<CvPoint3D32f>& input)
{
for (int i = 0; i < input.size(); i++)
{
std::cout << input[i].y << " ";
}
std::cout << std::endl;
}
而且TEST.CPP是:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include "cv.h"
#include "highgui.h"
#include "quicksort.hpp"
int main()
{
vector<CvPoint3D32f> input;
for(int r = 0; r <= 9;r++)
{
input.push_back(cvPoint3D32f(2.0f+r,2.1f+r,3.1f+r));
}
std::cout << "Input: ";
print(input);
return 0;
}
但我發現了這樣的錯誤:
quicksort.hpp:4: error: expected initializer before ‘<’ token
test.cpp: In function ‘int main()’:
test.cpp:22: error: ‘print’ was not declared in this scope
test.cpp:22: error: expected primary-expression before ‘>’ token
有沒有可能幫助我弄清楚爲什麼我得到這個錯誤?
我使用的是Debian Etch(Linux)上,G ++(gcc版本4.1.2 20061115(搶鮮)(Debian的4.1.1-21))和OpenCV 0.9.7-4
'print'不正確。 「模板」標題在哪裏? –
iammilind
只是改變'打印'到'打印' –
sashang
'vector'應該'std :: vector' – Naveen