473,837 Members | 1,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Declaring Template Classes that take Multiple Nested Templates as Parameters

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 class B has an instance of
template class A, which has some base type T (usually int or double).
However, the base type T is important to calculations in B, so I would
like to obtain access to the type for further variable declaration
within B. Below is a simplified version of my best attempt at the
syntax. I'm compiling under XCode 2.0 on Mac OS X version 10.4.6 using
GCC 4. Error messages have been commented in after lines in which they
occur:
//=============== =============== ===========
#include <iostream>
#include <vector>

template <typename T> class A
{
typedef T base_type;

public:
base_type get_item(int index)
{
return data_(index);
}

private:
std::vector<bas e_type> data_;
};

template <template <typename T> class A> class B
{
typedef T base_type; // error: 'T' does not name a type
typedef A<base_type> Atype; // error: 'base_type' was not declared
in this scope

public:
base_type get_item(int index)
{
return data_.get_item( index);
}

private:
Atype data_;

};
//=============== =============== ===========
Is there any way to gain access to these nested template parameters
from within class B? Is there a better way to get this same
functionality without intimate knowledge of A's types? Am I just
making some syntax error in the template class declaration?

Thanks for the help!

Jun 9 '06 #1
2 3347

pag...@gmail.co m wrote:
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 class B has an instance of
template class A, which has some base type T (usually int or double).
However, the base type T is important to calculations in B, so I would
like to obtain access to the type for further variable declaration
within B. Below is a simplified version of my best attempt at the
syntax. I'm compiling under XCode 2.0 on Mac OS X version 10.4.6 using
GCC 4. Error messages have been commented in after lines in which they
occur:
//=============== =============== ===========
#include <iostream>
#include <vector>

template <typename T> class A
{
typedef T base_type;

public:
base_type get_item(int index)
{
return data_(index);
}

private:
std::vector<bas e_type> data_;
};

template <template <typename T> class A> class B
{
typedef T base_type; // error: 'T' does not name a type
typedef A<base_type> Atype; // error: 'base_type' was not declared
in this scope

public:
base_type get_item(int index)
{
return data_.get_item( index);
}

private:
Atype data_;

};
//=============== =============== ===========
Is there any way to gain access to these nested template parameters
from within class B? Is there a better way to get this same
functionality without intimate knowledge of A's types? Am I just
making some syntax error in the template class declaration?

Thanks for the help!


The template parameter T that you have defined in the template class B
is really a template parameter for the template template parameter A.

It isnt visible outside. In many ways it is just a holder when
declaring a template template parameter and infact if you dont refer to
it again, you dont even need to have a name for that.

anyway try this.
template <typename T> class A
{
typedef T base_type;

public:
base_type get_item(int index)
{
return data_(index);
}

private:
std::vector<bas e_type> data_;

};

template < typename T, template <typename> class A> class B
{
typedef T base_type; // error: 'T' does not name a type

typedef A<base_type> Atype; // error: 'base_type' was not
declared in this scope

public:
base_type get_item(int index)
{
return data_.get_item( index);
}
private:
Atype data_;
};

Jun 9 '06 #2
am******@gmail. com wrote:
pag...@gmail.co m wrote:
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 class B has an instance of
template class A, which has some base type T (usually int or double).
However, the base type T is important to calculations in B, so I would
like to obtain access to the type for further variable declaration
within B. Below is a simplified version of my best attempt at the
syntax. I'm compiling under XCode 2.0 on Mac OS X version 10.4.6 using
GCC 4. Error messages have been commented in after lines in which they
occur:
//=============== =============== ===========
#include <iostream>
#include <vector>

template <typename T> class A
{
typedef T base_type;

public:
base_type get_item(int index)
{
return data_(index);
}

private:
std::vector<bas e_type> data_;
};

template <template <typename T> class A> class B
{
typedef T base_type; // error: 'T' does not name a type
typedef A<base_type> Atype; // error: 'base_type' was not declared
in this scope

public:
base_type get_item(int index)
{
return data_.get_item( index);
}

private:
Atype data_;

};
//=============== =============== ===========
Is there any way to gain access to these nested template parameters
from within class B? Is there a better way to get this same
functionality without intimate knowledge of A's types? Am I just
making some syntax error in the template class declaration?

Thanks for the help!


The template parameter T that you have defined in the template class B
is really a template parameter for the template template parameter A.

It isnt visible outside. In many ways it is just a holder when
declaring a template template parameter and infact if you dont refer to
it again, you dont even need to have a name for that.

anyway try this.
template <typename T> class A
{
typedef T base_type;

public:
base_type get_item(int index)
{
return data_(index);
}

private:
std::vector<bas e_type> data_;

};

template < typename T, template <typename> class A> class B
{
typedef T base_type; // error: 'T' does not name a type

typedef A<base_type> Atype; // error: 'base_type' was not
declared in this scope

public:
base_type get_item(int index)
{
return data_.get_item( index);
}
private:
Atype data_;
};


Or...

template <typename T> class A
{
public:
typedef T base_type; // now public

base_type get_item(int index)
{
return data_(index);
}
private:
std::vector<bas e_type> data_;
};

template <class A> class B
{
typedef typename A::base_type base_type;

public:
base_type get_item(int index)
{
return data_.get_item( index);
}
private:
A data_;
};

Cheers! --M

Jun 9 '06 #3

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

Similar topics

8
1960
by: Thomas Heller | last post by:
I need to convert C preprocessor definitions into python code. The definitions are dumped out of gccxml (see http://www.gccxml.org) , running over the windows header files (for example). This creates output like this (some excerpts): #define DATABITS_8 ((WORD)0x0008) #define KEY_WRITE ((STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY) & (~SYNCHRONIZE)) #define MS_NBF "MNBF" #define PSN_FIRST (0U-200U)
4
2739
by: wkaras | last post by:
I would like to propose the following changes to the C++ Standard, the goal of which are to provide an improved ability to specify the constraints on type parameters to templates. Let me say from the start that my knowledge of compiler implementation is very limited. Therefore, my suggestions may have to be rejected because they are difficult or impossible to implement. The proposal is based on the concept of "type similarity". Type...
10
5543
by: Clay_Culver | last post by:
I have heard that it is possible to use classes + template magic to make standalone functions (or maybe just a functor which acts like a function) which can accept variable length arguments without using the elipse. For example, a funciton could take in 1 known type, then a variable list of other parameters: ReturnValueClass rvc = someFunction("Some known type", 1, 0.2, "string"); ReturnValueClass rvc2 = someFunction("Some known type...
3
2272
by: Steve | last post by:
Is there any way of specifying the startMode when using the xslTransform class? We are updating code which used msxml to the system.xml classes but can find no way to specify the startMode. We use this so that we can specify different templates to be used by the same xml node. Know that we could use global params, but would rather not have to update all teh stylesheets and any code that uses msxml and the same stylesheets.
3
2742
by: sks | last post by:
Hello all Is the usage of extern keyword valid for telling the compiler to NOT instantiate a template and to link it from an another binary? For example: Suppose module A's binary contains a template class called "myTemplate", for which there is an instantiation for 'int' type. Now suppose a class in module B binary wants to use this template
4
2028
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 specialize the function for say <int> but this for all possible classes (from class template) the code is here
2
2377
by: coolpint | last post by:
Can anyone kindly provide an explanation as to why the compiler does not "see" the function template in the contrieved code below? I think the argument deduction fails but can't figure out exactly what the problem is. Is it related to the fact that a nested class is involved? #include <iostream> using std::cout;
4
1759
by: festo | last post by:
Hi guys, I need to print a different footer depending on the template being printed. How do I test for the current template being processed in XSLT? Thanks, fes
9
3477
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
0
9842
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
10566
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
10623
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
10271
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
9398
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
7000
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();...
0
5668
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...
1
4474
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
3
3124
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.