473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Defining templated member function outside templated class

Hi there, I'm surprised the following construct seems to be illegal:

template< typename T >
struct A
{
template< typename K >
void do_some( const K& );
};

template< typename T >
template< typename K >
void A<T>::do_some<K>( const K& k )
{}

I have tried several compilers, include Comeau and they all fail to
compile. Is the above code not allowed by the current standard?

Regards,
Christian
Feb 13 '08 #1
5 1311
chhenning wrote:
Hi there, I'm surprised the following construct seems to be illegal:

template< typename T >
struct A
{
template< typename K >
void do_some( const K& );
};

template< typename T >
template< typename K >
void A<T>::do_some<K>( const K& k )
{}
template< typename T >
template< typename K >
void A<T>::do_some( const K& k )
{}

--
Ian Collins.
Feb 13 '08 #2
chhenning wrote:
Hi there, I'm surprised the following construct seems to be illegal:

template< typename T >
struct A
{
template< typename K >
void do_some( const K& );
};

template< typename T >
template< typename K >
void A<T>::do_some<K>( const K& k )
{}

I have tried several compilers, include Comeau and they all fail to
compile. Is the above code not allowed by the current standard?
No, but only becase it is wrong. :-)

The code do_some<Kwould indicate a specialization of the function,
which is not allowed. You should instead try:

template< typename T >
template< typename K >
void A<T>::do_some( const K& k )
{}

Bo Persson
Feb 13 '08 #3
On 2008-02-13 19:04, chhenning wrote:
Hi there, I'm surprised the following construct seems to be illegal:

template< typename T >
struct A
{
template< typename K >
void do_some( const K& );
};

template< typename T >
template< typename K >
void A<T>::do_some<K>( const K& k )
{}

I have tried several compilers, include Comeau and they all fail to
compile. Is the above code not allowed by the current standard?
I do not know why this is illegal (neither the motivation nor the
chapter and verse of the standard) but the following works (in VC++ 2008
Express):

template< typename T >
template< typename K >
void A<T>::do_some( const K& k )
{}

--
Erik Wikström
Feb 13 '08 #4
Erik Wikström wrote:
On 2008-02-13 19:04, chhenning wrote:
>Hi there, I'm surprised the following construct seems to be illegal:

template< typename T >
struct A
{
template< typename K >
void do_some( const K& );
};

template< typename T >
template< typename K >
void A<T>::do_some<K>( const K& k )
{}

I have tried several compilers, include Comeau and they all fail to
compile. Is the above code not allowed by the current standard?

I do not know why this is illegal (neither the motivation nor the
chapter and verse of the standard) but the following works (in VC++ 2008
Express):
It appears as a partial specialisation.

--
Ian Collins.
Feb 13 '08 #5
Thank you all!
On Feb 13, 1:34*pm, Ian Collins <ian-n...@hotmail.comwrote:
Erik Wikström wrote:
On 2008-02-13 19:04, chhenning wrote:
Hi there, I'm surprised the following construct seems to be illegal:
template< typename T >
struct A
{
* *template< typename K >
* *void do_some( const K& );
};
template< typename T >
template< typename K >
void A<T>::do_some<K>( const K& k )
{}
I have tried several compilers, include Comeau and they all fail to
compile. Is the above code not allowed by the current standard?
I do not know why this is illegal (neither the motivation nor the
chapter and verse of the standard) but the following works (in VC++ 2008
Express):

It appears as a partial specialisation.

--
Ian Collins.- Hide quoted text -

- Show quoted text -
Feb 13 '08 #6

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

Similar topics

1
by: Rich | last post by:
Hi, I have a query regarding VC6 and its handling of templated copy constructors. Here goes: Take a look at the following code sample... template<class _Ty, size_t t_uiSize = 10 > class...
9
by: Jon Wilson | last post by:
I have a class which needs to accumulate data. The way we get this data is by calling a member function which returns float on a number of different objects of different type (they are all the...
4
by: Lionel B | last post by:
Greetings, The following code: <code> template<typename T> class A { protected:
6
by: Dan Huantes | last post by:
I was presented a problem today where a class had member variable that was an object of a templated class. The class wanted to instantiate the object as a private member variable and call a...
9
by: shaun | last post by:
Dear all, I realized an error in a previous post, I reproduce it here because I'm still not sure how to solve it: I want to make a templated function which points to one-past-the-end of a...
11
by: Matthias | last post by:
Hello, templated virtual member functions are not allowed. Now I am searching for a good workaround for this problem, but I can't find any. Here's my problem: class Base { template...
2
by: Amadeus W. M. | last post by:
I have a bunch of templated functions: template <class Type_t> double f2(Type_t x) { return 2*x; } template <class Type_t> double f3(Type_t x) { return 3*x; }
2
by: mattjgalloway | last post by:
I'm having some problems with a templated member function of a templated class. Unfortunately I can't replicate it with a simple example so I know something odd must be going on!!! Basically it's...
3
card
by: card | last post by:
Ah, the joy of generic programming. Ok. Here's my problem. I have a templated class with a internally defined structure type. Within the class, I have some member functions whose return value is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.