0

I'm trying to compile a c++ program that i wrote myself. And I'm having trouble compiling it.

The quicksort.hpp file is:

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

    }

And test.cpp is:

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

But I'm getting error like this:

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

Is it possible to kindly help me figure out why I'm getting this error?

I'm using Debian Etch(Linux), g++(gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)) and opencv 0.9.7-4

1 Answers1

1

Just say:

void print(vector<CvPoint3D32f>& points){

This would solve the problem. If not you need to declare a template, and if really necessary look into template specialization for your CvPoint3D32f, but this would be overkill.

pippin1289
  • 4,861
  • 2
  • 22
  • 37
  • Thanks to you all for answer. I want to make two print() function. One for CvPoint3D32f and the other for CvPoint3D32f. So I was wondering if I can use template specialization for this. Is it possible? Again thanks. –  May 17 '12 at 04:29
  • Yes, here is a good link to get you started. http://www.cprogramming.com/tutorial/template_specialization.html But basically you need to say template void Print(vector& v) for the basic template styles. Then there are additional things you do to create specialization. Check the tutorial. – pippin1289 May 17 '12 at 04:31