2012-05-17 82 views
0

我想編譯一個我編寫自己的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

+4

'print '不正確。 「模板」標題在哪裏? – iammilind

+2

只是改變'打印'到'打印' – sashang

+2

'vector'應該'std :: vector' – Naveen

回答

2

只是說:

void print(vector<CvPoint3D32f>& points){ 

這會解決問題。如果沒有,你需要聲明一個模板,如果真的有必要研究你的CvPoint3D32f的模板專門化,但這將是矯枉過正。

+0

感謝大家的回答。我想製作兩個print()函數。一個用於CvPoint3D32f,另一個用於CvPoint3D32f。所以我想知道如果我可以使用模板專業化。可能嗎?再次感謝。 – mvr950

+0

是的,這裏是一個很好的鏈接,讓你開始。 http://www.cprogramming.com/tutorial/template_specialization.html但基本上你需要說模板無效打印(矢量&V)的基本模板樣式。然後還有其他的事情可以用來創建專業化。檢查教程。 – pippin1289

+0

非常感謝您回答我的問題。 – mvr950

相關問題