473,402 Members | 2,055 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,402 software developers and data experts.

Nested class templates and incomplete type error

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?

-------------------------------------------------------------------
template <typename Xstruct Outer {

template <typename Ystruct Inner {};

};

template <struct Outer<int{ // If this full specialization is
removed, the compilation succeeds.

template <typename Y struct Inner {};

};

template <typename T>
struct Foo: Outer<T>::Inner<T{};

int main()
{
Foo<into;
return 0;
}
-------------------------------------------------------------------

Interestingly, if I remove the full specialization, the compilation
succeeds, to add to my confusion.

Thanks

Aug 29 '07 #1
5 5512
Belebele wrote:
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?

-------------------------------------------------------------------
template <typename Xstruct Outer {

template <typename Ystruct Inner {};

};

template <struct Outer<int{ // If this full specialization is
removed, the compilation succeeds.

template <typename Y struct Inner {};

};

template <typename T>
struct Foo: Outer<T>::Inner<T{};
Try

template <typename T>
struct Foo: Outer<T>:: template Inner<T{};
// ^^^^^^^^^^
>
int main()
{
Foo<into;
return 0;
}
-------------------------------------------------------------------

Interestingly, if I remove the full specialization, the compilation
succeeds, to add to my confusion.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 29 '07 #2
Try
>
template <typename T>
struct Foo: Outer<T>:: template Inner<T{};
// ^^^^^^^^^^
Right on the money, as always. What's the issue here?

Aug 29 '07 #3
Belebele wrote:
>Try

template <typename T>
struct Foo: Outer<T>:: template Inner<T{};
// ^^^^^^^^^^

Right on the money, as always. What's the issue here?
The compiler needs help determining that 'Inner' member of
'Outer<T>' is a template and that the meaning of the '<' after
it is the beginning of the template argument list and not the
comparison operator.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 29 '07 #4
The compiler needs help determining that 'Inner' member of
'Outer<T>' is a template and that the meaning of the '<' after
it is the beginning of the template argument list and not the
comparison operator.
Is there a legal construct that makes the use of the Inner class
template ambiguous if the "template" word is not used is this context?

Aug 29 '07 #5
Belebele wrote:
>The compiler needs help determining that 'Inner' member of
'Outer<T>' is a template and that the meaning of the '<' after
it is the beginning of the template argument list and not the
comparison operator.

Is there a legal construct that makes the use of the Inner class
template ambiguous if the "template" word is not used is this context?
No, I don't believe there is. But that's the whole point. The C++
compiler cannot pick the meaning of the syntax based on its validity.

What if your 'Outer' specialisation for this particular 'T' would have
a member 'Inner' that is not a template, but instead, say, a static
constant of type 'size_t'? The expression 'Outer<T>::Inner < blah'
would be a valid expression (in some other context). The compiler
needs a nudge from you to help it interpret the _intention_. Don't
put the burden of guessing what your intention might have been onto
the poor compiler, it's already got its hands full.

But then again, I am not a compiler writer, nor am I formally educated
in computer language theory, so take whatever I say with a fistful of
salt.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 29 '07 #6

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

Similar topics

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:
8
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. ...
4
by: Schüle Daniel | last post by:
Hello all, my question is basically wheather it's possible to have nested templates .. I mean the following if there are one templ. class and one global templ. function is it possible to...
2
by: pagekb | last post by:
Hello, I'm having some difficulty compiling template classes as containers for other template objects. Specifically, I have a hierarchy of template classes that contain each other. Template...
7
by: alex221 | last post by:
In need to implement a tree structure in which every node has arbitrary number of children the following code has come into mind: using std::list; template < class Contents class Tree_node{ ...
1
by: Helge | last post by:
I have a class nested in a template class and a function in the template class which returns the nested class type. I get compile error when compiling with the function definition outside the class...
10
by: SpreadTooThin | last post by:
I am having trouble getting a piece of code to compile on VC++ 6.0... Compiles fine on MAC OS X under X-Code.... #include <list> class myClass { private: std::string name;...
3
by: jdurancomas | last post by:
Dear all, I'm trying to declare the operator++ to a nested class. The nested class is not template but the container it is. The code used in teh sample program is included bellow: ...
15
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
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
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
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
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
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
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
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
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...

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.