473,480 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

'function' : cannot be explicitly specialized error

Say I have a class template as follows

template<typename T>
class foo
{
public:
void test();
};

template<typename T>
void foo<T>::test()
{
// function implementation
}

Now if i want to specialize it for say strings, I would do it as
follows
template<>
class foo<string>
{
public:
void test();
};

template<//Gives a error "function cannot be specialized"
void foo<string>::test()
{
// function implementation
}

My question is why do I need to omit the "template<" for functions
of specialized template class? I am trying this with Visual C++
Express 2005 edition.

Jul 11 '07 #1
2 3693
Aarti wrote:
Say I have a class template as follows

template<typename T>
class foo
{
public:
void test();
};

template<typename T>
void foo<T>::test()
{
// function implementation
}

Now if i want to specialize it for say strings, I would do it as
follows
template<>
class foo<string>
{
public:
void test();
};

template<//Gives a error "function cannot be specialized"
void foo<string>::test()
{
// function implementation
}

My question is why do I need to omit the "template<" for functions
of specialized template class? I am trying this with Visual C++
Express 2005 edition.
Because the standard says so. Note that foo<string>::test (assuming string
is a type) is not a template. It is an ordinary member function of the
specialised template foo.

--
rbh
Jul 11 '07 #2
On Jul 11, 4:47 am, Robert Bauck Hamar <roberth+n...@ifi.uio.no>
wrote:
Aarti wrote:
Say I have a class template as follows
template<typename T>
class foo
{
public:
void test();
};
template<typename T>
void foo<T>::test()
{
// function implementation
}
Now if i want to specialize it for say strings, I would do it as
follows
template<>
class foo<string>
{
public:
void test();
};
template<//Gives a error "function cannot be specialized"
void foo<string>::test()
{
// function implementation
}
My question is why do I need to omit the "template<" for functions
of specialized template class? I am trying this with Visual C++
Express 2005 edition.

Because the standard says so. Note that foo<string>::test (assuming string
is a type) is not a template. It is an ordinary member function of the
specialised template foo.

--
rbh- Hide quoted text -

- Show quoted text -
Ok Got it. Thanks!!!

Jul 12 '07 #3

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

Similar topics

9
4931
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
3
2097
by: Dave | last post by:
Hello all, I am trying to create a full specialization of a member function template of a class template. I get the following errors: Line 29: 'foo<T1>::bar' : illegal use of explicit...
1
1731
by: Arne Petersen | last post by:
Hy, I've got a problem with member function templates compiled into libraries. I'm trying to get a library collection (coded for GNU gcc, where its compiled completly) being compiled on Visual...
5
6563
by: Levent | last post by:
Hi, Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1): #include <iostream> template<class T, unsigned N> struct Foo { void func(); }; template<class T, unsigned N>
4
3301
by: Joseph Turian | last post by:
Hi, What is the correct syntax to get the bar<T>::f<int, unsigned>() function to compile in the following fragment? Thanks, Joseph class foo {
2
2293
by: pookiebearbottom | last post by:
Just trying to learn some things about templates. Was wondering how boost::tupple really works, but the headers were a bit confusing to me. I know you get do something like the following, just...
2
2046
by: Simon G Best | last post by:
Hello! I'm trying to specialize a member function template of a class template, like this:- template<typename Tclass thingy { public: template<typename UT f (const U &) const; };
7
236
by: sheffmail | last post by:
I have the following code: template <class T> struct MyS { }; template<class T> inline const T& function(const std::locale& loc) {
1
1472
by: sunil | last post by:
Hello, I have a template class as follows which has a static function called foo, as you see below the class declaration, there are specializations for foo for different specializations of T, the...
0
7049
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
6912
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
7092
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
6981
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...
0
5348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4488
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
3000
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
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.