473,804 Members | 3,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Redefining nested class on class specialization.

The following code fails to compile. My intention is to provide
different definitions for a nested class for a class template partial
specialization. Here it is:
template <typename , int class Outer {
public:
class Inner;
};

template <int iclass Outer<int, i>::Inner {};

template <int iclass Outer<double, i>::Inner {};

Do you have any idea why?

Thanks.

Nov 2 '07 #1
4 1876
Belebele wrote:
The following code fails to compile. My intention is to provide
different definitions for a nested class for a class template partial
specialization. Here it is:
template <typename , int class Outer {
public:
class Inner;
};

template <int iclass Outer<int, i>::Inner {};

template <int iclass Outer<double, i>::Inner {};

Do you have any idea why?
The rule is, "you cannot specialise the member of a class template
without first specialising the template".

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 2 '07 #2
The rule is, "you cannot specialise the member of a class template
without first specialising the template".
Don't quite get it. I am able to specialize a member function without
specializing the entire class template. The code below compiles OK:

template <typename struct F {
void f();
};

template <>
void F<int>::f() {};

template <>
void F<double>::f() {};
I thought I could do the same with an inner class. If not, I would use
some indirection to achieve the effect I want. Redefining the inner
class would have been more direct.

Nov 2 '07 #3
Belebele wrote:
>The rule is, "you cannot specialise the member of a class template
without first specialising the template".

Don't quite get it. I am able to specialize a member function without
specializing the entire class template. The code below compiles OK:

template <typename struct F {
void f();
};

template <>
void F<int>::f() {};

template <>
void F<double>::f() {};
I thought I could do the same with an inner class. If not, I would use
some indirection to achieve the effect I want. Redefining the inner
class would have been more direct.
I believe you're confusing full specialisation with partial. A full
specialisation is *not* a template. A partial specialisation is still
a template. Try specialising your F::f for, say, all pointers.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 2 '07 #4
I believe you're confusing full specialisation with partial. A full
specialisation is *not* a template. A partial specialisation is still
a template. Try specialising your F::f for, say, all pointers.

Now I get it. I was mixing them up. Thanks.

Nov 2 '07 #5

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

Similar topics

6
2644
by: jesse | last post by:
I am frustrated by class specialization. i don't think it helps me a lot. suppose we have template <class T> class Talkative { T& t; public:
3
2069
by: Andriy Shnyr | last post by:
Let us consider the following nested templates case: template<typename T> class Outer{ public: template<typename U> class Inner{ public:
0
1498
by: Patrick Kowalzick | last post by:
Dear all, the following code is illegeal (but compiles with MSVC 7.1): // *** illegal *** struct outer0 { template<typename inner_var> struct inner { }; template<>
0
1482
by: Imre | last post by:
I'm planning to create a macro-based property system (reflection, automatic serializing for properties, that kind of stuff). The system would involve writing some PROPERTY(propName) macros between a BEGIN_CLASS(ThisClass) and an END_CLASS() macro. The PROPERTY macros should somehow know ThisClass, and that's where it start to get tricky. A #define ThisClass would of course help, but I'd rather make it part of the BEGIN_CLASS macro, and...
5
5549
by: Belebele | last post by:
The code below does not compile under g++. There is an outer class template that contains and inner class template. The outer class template is fully specialized for int. Then a separate Foo class template inherits from the inner. The compiler indicates that the inner class is incomplete when used as the base class of the inner class template. Why? -------------------------------------------------------------------
9
3475
by: stephen.diverdi | last post by:
Can anyone lend a hand on getting this particular template specialization working? I've been trying to compile with g++ 4.1 and VS 2005. //------------------------------------------------------------------ // my regular glass class A { }; // my templated class
2
7703
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
5
3744
by: huili80 | last post by:
For example, like in the following, the part commented out was intended as partial spectialzation, but it would even compile. Is it even legal to partially specialize a nested template class inside another template class? template < typename T > struct A { template < typename U > struct B
2
2769
by: er | last post by:
hello, here's my problem: struct A{}; struct B{}; struct T{}; struct outer{
0
10571
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10326
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10317
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9143
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5520
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
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 we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.