September 18th, 2010, 06:57 PM
C++ Template Weird problem, please help
I am using C++ templates and working on a library where a problem with C++ templates appeared. I simulated that error here with simple program for your help.
using namespace std;
cout<<"X in Vector\n";
void X(int m)
cout<<"X in Matrix\n";
template <typename T>
int gg(T a, bool tt)
Now using gcc on linux, it compiles that cannot find V.X(int) for Vector instantiation which should not be as it is in else block. Exact errors are as below:
test.cpp: In function ‘int gg(T, bool) [with T = Vector]’:
test.cpp:38: instantiated from here
test.cpp:31: error: no matching function for call to ‘Vector::X(int)’
test.cpp:8: note: candidates are: void Vector::X()
test.cpp: In function ‘int gg(T, bool) [with T = Matrix]’:
test.cpp:39: instantiated from here
test.cpp:29: error: no matching function for call to ‘Matrix::X()’
test.cpp:18: note: candidates are: void Matrix::X(int)
Please help me as I don't why compiler do it. Even I have tried using bool as template parameter but still it was expanding else block also. What should be a viable alternative???
Thanks in advance
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.