Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
A member function template is tried to be called from an other separate function template.
-> Compiler says something like this: "parse error before `>' ".I use Linux g++ (version 2.96 or 2.95).
Is it possible to make this working somehow?
Would "typename" or some other kinds of words help somehow?
(E.g. I needed to add "typeName" before "aaT::someType x;" to compile that part of code successfully.)My test code
The problem is on line "varAa.foo<int>();" (it do not compile).template <typename aaT>
void function1 ()
{
typename aaT::someType x;
aaT varAa;
varAa.foo<int>();
}
class myClass {
public:
typedef int someType;
template<typename T1>
void foo () {}
};
int main() {
function1<myClass>();
}And, even if I do not create any instances of that function template (even if I do not call it at all), it still complains about the same line. E.g. if I do not execute anything at all in the main program, then it still complains about the mentioned line ("varAa.foo<int>();").
int main() {
// comment this line out:
//function1<myClass>();
}It seems that the compiler wants the critical line of code ("varAa.foo<int>();") to be compiled "too early". The compiler should "wait" for the template instantiation (or something like that?). I should somehow ask compiler to wait for the instantiation of "template <typename aaT> void function1()"? The member function template "foo" will be found from "varAa" (from myClass) just a little bit later!
And of course, if I execute foo straight from myClass object (and remove the critical line of code "varAa.foo<int>();"), then the function works normally (this should work ok):
int main() {
myClass myObj;
myObj.foo<int>();
}

I got an answer from a code expert.
This helps:
varAa.template foo<int>();C++ standard says that without the keyword "template", compiler assumes that the name is a non-template.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |