Computing.Net > Forums > Programming > Function template call from an othe

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Function template call from an othe

Reply to Message Icon

Name: userName76
Date: September 28, 2004 at 22:41:45 Pacific
OS: Linux
CPU/Ram: --
Comment:

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>();
}



Sponsored Link
Ads by Google

Response Number 1
Name: userName76
Date: September 29, 2004 at 00:57:18 Pacific
Reply:

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.


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Function template call from an othe

call VB6.0 program from AS400/RPG www.computing.net/answers/programming/call-vb60-program-from-as400rpg/18143.html

vb6 - gettin maximum from an array www.computing.net/answers/programming/vb6-gettin-maximum-from-an-array/14220.html

Extracting data from an array in C www.computing.net/answers/programming/extracting-data-from-an-array-in-c/8130.html