Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C++ Programming

Template in Template Problem


The following is a much simplified version of some code that is
refusing to compile.  Is there anything technically wrong with the
code?

class ClassWithTemplateFunction
{
   public:
      template<class T> inline void SomeSillyFunction(T value) const
         {
         }

};

template <typename T> void TemplateFunction( ClassWithTemplateFunction
& rC, T value)
   {
   rC.SomeSillyFunction< T >( value );
   }

int main()
{
   ClassWithTemplateFunction  C;

   int value = 0;

   TemplateFunction<int>(C, value);

   return 0;

}

The error I get from the compiler is " Parse error before '>' " on the
line: rC.SomeSillyFunction< T >( value );

Any help would be appreciated.

Try:

rC.template SomeSillyFunction< T >( value );

On 16 Feb, 16:19, "easy" <chris.mich@lmco.com> wrote:

What compiler are you using?

Using MS Visual Studio 2005 your code compiles with no errors and when
I step through in the debugger it follows the expected path. Also, the
code compiles without errors in Comeau online (can't execute it there
to see what happens).

Gavin Deane

On Feb 16, 10:28 am, "Gavin Deane" <deane_ga@hotmail.com> wrote:

compiler = gcc 3.3.5
On Feb 16, 10:23 am, Rolf Magnus <ramag@t-online.de> wrote:

I am unfamilliar with inserting the operator "template" in the
function call.  I will try it.
On Feb 16, 10:23 am, Rolf Magnus <ramag@t-online.de> wrote:

rC.template SomeSillyFunction< T >( value ); compiles.  I will have to
study more the keyword "template".

My fix is: rC.SomeSillyFunction( value );
This way the compiler is left to figure out how to instantiate the
template. Your fix is rather confusing? Why is adding 'template' here a
resolution? Can you make an analogy as an explanation?
* Fei Liu:

> Rolf Magnus wrote:

>> Try:

>> rC.template SomeSillyFunction< T >( value );

> My fix is: rC.SomeSillyFunction( value );
> This way the compiler is left to figure out how to instantiate the
> template. Your fix is rather confusing? Why is adding 'template' here a
> resolution? Can you make an analogy as an explanation?

Using the 'template' keyword is a more general fix, because it lets you
choose the template parameter(s) independent of the argument's type(s).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Fei Liu wrote:
> Rolf Magnus wrote:
>> easy wrote:
>> Try:

>> rC.template SomeSillyFunction< T >( value );

> My fix is: rC.SomeSillyFunction( value );
> This way the compiler is left to figure out how to instantiate the
> template. Your fix is rather confusing? Why is adding 'template' here a
> resolution? Can you make an analogy as an explanation?

I thought template in this context was a FAQ, kind of like typedef
typename xxx.  Apparently not.
On Feb 16, 12:21 pm, Fei Liu <fei@aepnetworks.com> wrote:

Once I knew what to look for I found this discussion.  Very helpful.
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/248...
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc