Templates: template function not playing well with class's template member function?

When you refer to a template that is a member of dependent type, you have to prepend it with a keyword template This is how the call to getResult inside printStuff should look.

When you refer to a template that is a member of dependent type, you have to prepend it with a keyword template. This is how the call to getResult inside printStuff should look size_t value = a. Template getResult(); This is similar to using the keyword typename when referring to nested typenames in a dependent type.

For some reason, the bit about typename with nested types is rather well-known, but the similar requirement for template with nested templates is relatively unknown. Note that the general syntax structure is a bit different though. The typename is always put in front of the full name of the type, while template is inserted in the middle.

Again, this is only necessary when you are accessing a template member of a dependent type, which in the above example would be A in printStuff. When you call foo. GetResult in main the type of foo is not dependent, so there's no need to include the template keyword.

4 Wow, just I when I thought I knew everything there was to know about C++ ... – Frank Krueger Nov 5 '09 at 19:16 2 Thanks! That's the most bizarre syntax I've ever seen in C++. – Seth Johnson Nov 5 '09 at 19:17 1 Somehow VC++ is quite lenient about it (ie, you can often get away without it), but gcc is definitely not!

– Matthieu M. Nov 6 '09 at 7:15 Totally agree with you guys on all three points, except I found gcc to also be lenient until cross-compiling for ARM with CodeSourcery. – DataGraham Oct 19 at 13:32.

Your code is ill-formed according to C++ Standard 14.2/4: When the name of a member template specialization appears after . Or -> in a postfix-expression, or after nested-name-specifier in a qualified-id, and the postfix-expression or qualified-id explicitly depends on a template-parameter (14.6.2), the member template name must be prefixed by the keyword template. Otherwise the name is assumed to name a non-template.So, you should write size_t value = a.

Template getResult().

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions