Problems of template?

my OS is window xp sp3
compiler? : GCC 4.5(minGW)
IDE : code blocks 10.05
I am using the library openCV2.2

below is my code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
template<typename T>
void testMC(cv::Mat_<T>& One, int sum)
{
 int* ptr2 = &One.ptr<int>(0)[0]; //assig the address of the first pixel
                 // to the U* ptr2
 //this function would cause some problem
 //if I simply neglect typename U but explicitly state the 
 //type of One, every thing should be fine
 //like void testMC(cv::Mat_<cv::Vec3i>& One, int sum), this one is fine
}

void testMultiChannel_CV()
{
  using std::cout;
  //Vec3i = Vec(int, 3)
  cv::Mat_<cv::Vec3i> One(10, 10); //could treat this as
                    //type int One[3][10][10] array
  testMC(One, sum);
  int* ptr2 = &One.ptr<int>(0)[0]; //this is OK
}

the error message is

expected primary-expression before 'int'|


How could I solve the problem? Thanks a lot
Last edited on
The parser doesn't know that One.ptr is a template function ( since it may depend on what T is )
You need to tell it that the '<' would be the beginning of a template parameter and not the less-than operator.
That is done this way: &One.template ptr<int>(0)[0];
Thanks a lot
Topic archived. No new replies allowed.