473,387 Members | 1,423 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,387 software developers and data experts.

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 1847
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
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
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
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
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...
5
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...
9
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. ...
2
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
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...
2
by: er | last post by:
hello, here's my problem: struct A{}; struct B{}; struct T{}; struct outer{
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.