2012-05-17 19 views
0

직접 작성한 C++ 프로그램을 컴파일하려고합니다. 그리고 컴파일하는데 문제가 있습니다.C++ 컴파일 오류 : '<'토큰 앞에 예상 초기화 자

quicksort.hpp 파일은 다음과 같습니다

#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; 
    } 

하지만이 같은 오류를 받고 있어요 :

#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에

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 

친절하게도 알아낼 수 있습니까? 왜이 오류가 발생합니까?

내가 데비안 엣지 (리눅스), g ++ (GCC의 4.1.2 20061115 (시험판 버전) (데비안 4.1.1-21)) 및 OpenCV의를 사용하고 0.9.7-4

+4

'print '가 올바르지 않습니다. 'template' 헤더는 어디에 있습니까? – iammilind

+2

'print '을'print'로 바꾼다 – 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하지만 기본적으로 템플릿을 말할 필요가 기본 템플릿 스타일에 대한 void 인쇄 (벡터 & v) 인쇄. 그런 다음 전문화를 위해 추가로 수행해야 할 작업이 있습니다. 튜토리얼을 확인하십시오. – pippin1289

+0

내 질문에 답변 해 주셔서 감사합니다. – mvr950

관련 문제