472,985 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,985 software developers and data experts.

Nested template type access

Greetings.

In a template class for which a template parameter may be another
template class, I would like to be have access to the type of the
nested template parameter. Hopefully the following example makes this
clearer:

// example1.cpp

template <typename T> struct A
{
typedef T param_type;
};

template <typename U> struct B
{
typedef U::param_type nested_param_type; // line 10
};

int main()
{
B< A<int> > b;
return 0;
}

My compiler (gcc) throws this out with:

test.cpp:10: error: ISO C++ forbids declaration of `param_type' with no
type
test.cpp:10: error: `::param_type' is not a valid declarator
test.cpp:10: error: parse error before `;' token

(for some reason, gcc seems to think I am trying to declare
`param_type'). On other hand, the following code compiles happily:

// example2.cpp

template <typename T> struct A
{
const static int n = 123;
};

template <typename U> struct B
{
const static int m = U::n;
};

int main()
{
B< A<int> > b;
return 0;
}

In both cases the declaration of B references an attribute of its
template parameter U (a type in example 1, a static data member in
example 2) which is known - for a particular instantiation of an object
of type B - at compile time. It's not clear to me why the former should
be acceptable and the latter not.

Any views?

--
Lionel B

Jul 22 '05 #1
3 3803

"Lionel B" <go****@lionelb.com> wrote in message
news:10**********************@c13g2000cwb.googlegr oups.com...
Greetings.

In a template class for which a template parameter may be another
template class, I would like to be have access to the type of the
nested template parameter. Hopefully the following example makes this
clearer:

// example1.cpp

template <typename T> struct A
{
typedef T param_type;
};

template <typename U> struct B
{
typedef U::param_type nested_param_type; // line 10


typedef typename U::param_type nested_param_type; // line 10

gcc (like any compliant compiler) is assuming that param_type is a static
data member. It is your responsibility to tell it different.

john
Jul 22 '05 #2
John Harrison wrote:
"Lionel B" <go****@lionelb.com> wrote in message
news:10**********************@c13g2000cwb.googlegr oups.com...
Greetings.

In a template class for which a template parameter may be another
template class, I would like to be have access to the type of the
nested template parameter. Hopefully the following example makes this clearer:

// example1.cpp

template <typename T> struct A
{
typedef T param_type;
};

template <typename U> struct B
{
typedef U::param_type nested_param_type; // line 10


typedef typename U::param_type nested_param_type; // line 10

gcc (like any compliant compiler) is assuming that
param_type is a static data member. It is your
responsibility to tell it different.


Thanks, John.

--
Lionel B

Jul 22 '05 #3

"Lionel B" <go****@lionelb.com> wrote in message
news:10**********************@c13g2000cwb.googlegr oups.com...
Greetings.

In a template class for which a template parameter may be another
template class, I would like to be have access to the type of the
nested template parameter. Hopefully the following example makes this
clearer:

// example1.cpp

template <typename T> struct A
{
typedef T param_type;
};

template <typename U> struct B
{
typedef U::param_type nested_param_type; // line 10
};


Should be

typedef typename U::param_type nested_param_type'

Rgds
d

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Jul 22 '05 #4

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

Similar topics

8
by: CoolPint | last post by:
I read in books that nested class cannot access private members of nesting class and vice versa unless they are made friends. Somehow, my compiler is letting my nested class member functions access...
2
by: CoolPint | last post by:
As a self-exercise, I am trying to write a generic Priority Queue, which would store any type and and accept any user-definable "priority" function. After much tinkering, I came up with...
5
by: Axter | last post by:
I'm fine tuning a scope_handle class that takes a policy class as the second template. http://code.axter.com/scope_handle.h Please see above link for full understanding of the problem. One...
1
by: Jacob N. Rohde | last post by:
Hi guys, I was under the assumption that the default type access modifier for classes/structs is internal. But the MCAD Study Guide (from MS even) says public?!?! (The Dr. GUI .NET tutorial from...
9
by: Mike | last post by:
Hi, Just a simple question: why the compiler doesn't report error when accessing a private member function inside a function having template type ? For example: #include<iostream> using...
1
by: Dusty1368 | last post by:
Good evening, I have this idea........ I want (someone) to design a template in Access or Excel (I was told it was these 2) and from which ever program data like date, time, location, and subject...
9
by: Adam Nielsen | last post by:
Hi all, I'm a bit confused about the syntax used to access a nested template class. Essentially I have a bunch of class types to represent different types of records in a database, and I want...
3
by: Auslander | last post by:
I'm new to VBA, and trying to learn how to write some code to open a word template from access and populate it using Document Properties. Here's my code: Private Sub OpenWindows_Click() Dim...
8
by: Ralf Goertz | last post by:
Hi, I want to do able to declare an object bar of a templated class foo where the actual template type of foo is only know at runtime: ----- #include <string> template <class Tclass foo {
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.