473,836 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Nested templates explicit specialization

Let us consider the following nested templates case:

template<typena me T>
class Outer{

public:
template<typena me U>
class Inner{

public:
void f();
};

};

Then the following specialization
template<> template<typena me U> void Outer<int>::Inn er<U>::f(){};
results in compile-time error (I've tried to compile it with gcc 3.2.2)

main.cpp:XXX: invalid use of undefined type `class Outer<int>::Inn er<U>'
main.cpp:XXX: declaration of `class Outer<int>::Inn er<U>'
main.cpp:XXX: template definition of non-template `void
Outer<int>::Inn er<U>::f()'

Can anyone help me to figure out the problem?

Thanks in advnace,
Andriy Shnyr

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:st*****@ ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]

Jul 22 '05 #1
3 2073
On Wed, 3 Dec 2003 17:35:21 +0000 (UTC), sh***@mailcity. com (Andriy
Shnyr) wrote:
Let us consider the following nested templates case:

template<typen ame T>
class Outer{

public:
template<typena me U>
class Inner{

public:
void f();
};

};

Then the following specialization
template<> template<typena me U> void Outer<int>::Inn er<U>::f(){};
results in compile-time error (I've tried to compile it with gcc 3.2.2)

main.cpp:XXX : invalid use of undefined type `class Outer<int>::Inn er<U>'
main.cpp:XXX : declaration of `class Outer<int>::Inn er<U>'
main.cpp:XXX : template definition of non-template `void
Outer<int>::Inn er<U>::f()'

Can anyone help me to figure out the problem?

Thanks in advnace,
Andriy Shnyr

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:st*****@ ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


template < typename O >
struct outer
{
template < typename I >
struct inner
{
void f();
};
};

template <>
struct outer<int>
{
template < typename I >
struct Inner
{
void f();
};
};

Cheers!


Jul 22 '05 #2
"Andriy Shnyr" <sh***@mailcity .com> wrote...
Let us consider the following nested templates case:

template<typena me T>
class Outer{

public:
template<typena me U>
class Inner{

public:
void f();
};

};

Then the following specialization
template<> template<typena me U> void Outer<int>::Inn er<U>::f(){};
results in compile-time error (I've tried to compile it with gcc 3.2.2)

main.cpp:XXX: invalid use of undefined type `class Outer<int>::Inn er<U>'
main.cpp:XXX: declaration of `class Outer<int>::Inn er<U>'
main.cpp:XXX: template definition of non-template `void
Outer<int>::Inn er<U>::f()'

Can anyone help me to figure out the problem?


If you need to specialise the outer class but keep the nested template
a template, you need to first declare the existence of 'Outer<int>::In ner'
template manually:

template<> class Outer<int> {
template<class U> class Inner {
public:
void f();
};
};

Otherwise you're declaring a member function of a class that doesn't
exist.

That's my take on it, anyway.

Victor
Jul 22 '05 #3
On 12/03/2003 11:35 AM, Andriy Shnyr wrote:
[snip]
main.cpp:XXX: invalid use of undefined type `class Outer<int>::Inn er<U>'
main.cpp:XXX: declaration of `class Outer<int>::Inn er<U>'
main.cpp:XXX: template definition of non-template `void
Outer<int>::Inn er<U>::f()'

Can anyone help me to figure out the problem?

IIRC, adding ::template Inner<U> solved the compile problem for me;
however, I found a problem with the produced code not selecting the
right specialization, as reported here:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13088

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:st*****@ ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]

Jul 22 '05 #4

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

Similar topics

15
2550
by: Robin Eidissen | last post by:
What I try to do is to iterate over two variables using template metaprogramming. I've specialized it such that when it reaches the end of a row ot starts on the next and when it reaches the last row it stops.. At least that's what I thought I did, but VC71 says "warning C4717: 'LOOP<0,1>::DO' : recursive on all control paths, function will cause runtime stack overflow". What's wrong? Here's the code: template<int M, int N>
1
1751
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 Studio .NET. The problem is that for gcc the template functions (members of a class) are explicitly instantiated in a cpp file that includes the classes .h and .cpp file. The VS compiler does not correctly bring together the function template...
0
1500
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<>
6
5679
by: Vyacheslav Lanovets | last post by:
Hello, All! I know that Explicit Instantiation actually emits code to obj files (so you can even export them from the module as plain functions or classes). But I found that MSVC7.1 compiler does the same in case of Explicit Specialization, so I either have to delcare specializations inline or move definitions to cpp file to avoid LNK2005 ("already defined") errors. Why is that?
1
1530
by: Thomas Barnet-Lamb | last post by:
I have a query concerning the handling of explicit specializations. Essentially, I want to know whether it is legal to take a template like >template<class X> typename X::A Foo(typename X::B, typename X::C) and specialise it in the case X takes some particular value, such as: >template<> typename Bar::A Foo<Bar>(typename Bar::B, typename Bar::C)
3
4009
by: Steven T. Hatton | last post by:
Has anybody here used explicit instantiation of templates? Has it worked well? Are there any issues to be aware of? -- NOUN:1. Money or property bequeathed to another by will. 2. Something handed down from an ancestor or a predecessor or from the past: a legacy of religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF, from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/
9
3476
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
7706
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
0
9820
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9671
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10845
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...
1
10592
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
10254
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9376
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...
1
7792
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6979
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3116
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.