473,505 Members | 13,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 Tinline void SomeSillyFunction(T value) const
{
}
};

template <typename Tvoid 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.

Feb 16 '07 #1
9 1206
easy wrote:
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 Tinline void SomeSillyFunction(T value) const
{
}
};

template <typename Tvoid 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 );

Feb 16 '07 #2
On 16 Feb, 16:19, "easy" <chris.mich...@lmco.comwrote:
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 Tinline void SomeSillyFunction(T value) const
{
}

};

template <typename Tvoid 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.
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

Feb 16 '07 #3
On Feb 16, 10:28 am, "Gavin Deane" <deane_ga...@hotmail.comwrote:
On 16 Feb, 16:19, "easy" <chris.mich...@lmco.comwrote:


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 Tinline void SomeSillyFunction(T value) const
{
}
};
template <typename Tvoid 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.

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- Hide quoted text -

- Show quoted text -
compiler = gcc 3.3.5

Feb 16 '07 #4
On Feb 16, 10:23 am, Rolf Magnus <ramag...@t-online.dewrote:
easy wrote:
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 Tinline void SomeSillyFunction(T value) const
{
}
};
template <typename Tvoid 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 );- Hide quoted text -

- Show quoted text -
I am unfamilliar with inserting the operator "template" in the
function call. I will try it.

Feb 16 '07 #5
On Feb 16, 10:23 am, Rolf Magnus <ramag...@t-online.dewrote:
easy wrote:
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 Tinline void SomeSillyFunction(T value) const
{
}
};
template <typename Tvoid 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 );- Hide quoted text -

- Show quoted text -

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

Feb 16 '07 #6
Rolf Magnus wrote:
easy wrote:
>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 Tinline void SomeSillyFunction(T value) const
{
}
};

template <typename Tvoid 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 );
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?
Feb 16 '07 #7
* 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?
Feb 16 '07 #8
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.

Feb 16 '07 #9
On Feb 16, 12:21 pm, Fei Liu <fei...@aepnetworks.comwrote:
Rolf Magnus wrote:
easy wrote:
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 Tinline void SomeSillyFunction(T value) const
{
}
};
template <typename Tvoid 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 );

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?- Hide quoted text -

- Show quoted text -
Once I knew what to look for I found this discussion. Very helpful.
http://groups.google.com/group/comp....ff203f27c5bfb0

Feb 17 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2592
by: C. Carbonera | last post by:
/* Hi, I have a problem with explicit instantiation of templates in Visual C++ 6.0. I have provided the source below. I have an example of a function template that produces incorrect output in...
6
2321
by: Adam Parkin | last post by:
Hello, all I'm having a problem with friend functions in a templatized Queue class I'm writing using linked lists. The problem is that I can't get the friend function to be able to access private...
7
2463
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M>...
7
2115
by: Lionel B | last post by:
Greetings. The following code compiles ok and does what I'd expect it to do: ---------- START CODE ---------- // test.cpp
3
4446
by: David Komanek | last post by:
Hi all, I am trying to learn more about how to use g++/Cygwin to produce dll files on WinXP. And I have a problem which at the first look seems to be an obvious dll-export problem, but I don't...
5
1698
by: Amit | last post by:
Greetings all, I am writing some code somehwat similar to the test code I have below. I am having a variety of issues with template specialization. I am not sure if this is related to something...
2
2740
by: Siegfried Weiss | last post by:
Hi guys, i give up finding a solution by reading or by trial & error. Hope, YOU can help me! (Sorry for my rather long posting.) Stroustrup says, that templates could be declared with - type...
3
3918
by: Chris | last post by:
I am having a very strange problem involving virtual functions in template classes. First of all, here is an extremely simplified structure of the two classes I am having problems with. ...
19
7885
by: aaragon | last post by:
Hi everyone. A very simple question. I would like to know what is better in terms of performance. I want to use a simple function to obtain the minimum of two values. One way could be using a...
3
3739
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.