473,748 Members | 7,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Template as an argument to a class

Greetings,

I am trying to create a template class called Matrix that operates on a
template class called complex.

Now of course complex is a template class and I want it to be the argument
for Matrix.

So I have something like:
template <class T> class complex {/*..*/}

then I want to use complex in Matrix like this:
template <class T2> class Matrix {/*..*/} where T2 is of type
complex<double> .

Has anyone ever done anything like that? I am using Solaris 2.6 OS with CC
ver 6.2.

Any help will be appreciated.

Thanks.
Jul 19 '05 #1
2 2007
Richard Cromer wrote:
Greetings,

I am trying to create a template class called Matrix that operates on
a template class called complex.

Now of course complex is a template class and I want it to be the
argument for Matrix.

So I have something like:
template <class T> class complex {/*..*/}

then I want to use complex in Matrix like this:
template <class T2> class Matrix {/*..*/} where T2 is of type
complex<double> .

Has anyone ever done anything like that? I am using Solaris 2.6 OS
with CC ver 6.2.


I think you will need template template parameters. I am not sure if Forte
6.2 supports it.

--
Attila aka WW
Jul 19 '05 #2
On Thu, 21 Aug 2003 07:51:56 -0400, "Richard Cromer"
<ri************ @kodak.com> wrote:
Greetings,

I am trying to create a template class called Matrix that operates on a
template class called complex.

Now of course complex is a template class and I want it to be the argument
for Matrix.

So I have something like:
template <class T> class complex {/*..*/}

then I want to use complex in Matrix like this:
template <class T2> class Matrix {/*..*/} where T2 is of type
complex<double >.

Has anyone ever done anything like that? I am using Solaris 2.6 OS with CC
ver 6.2.


Matrix<complex< double>/*note a space is required*/> m;
e.g.
Matrix<complex< double> > m;
Matrix<complex< double>> m;
is a syntax error, since the last >> is a right shift operator, where
you need two > tokens instead. This is considered a major problem with
the C++ "max munch" parsing (which grabs the biggest token available),
but there is an intention to fix it for the next version of the C++
standard.

Tom
Jul 19 '05 #3

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

Similar topics

2
6282
by: Elven | last post by:
Hi! I was trying to find the solution to this problem, but I don't think I could quite come up with the correct keywords to find it, since I'm pretty sure it's been asked before. In short, here's the situation (ignore missing namespaces, etc, since I'm not cut-pasting this..) // a.h template <class B>
8
11366
by: vpadial | last post by:
Hello, I want to build a library to help exporting c++ functions to a scripting languagge. The scripting language provides a function to register functions like: ANY f0() ANY f1(ANY) ANY f2(ANY, ANY) ANY f3(ANY, ANY, ANY)
3
2731
by: case2005 | last post by:
Can anyone help with the following, I don't know if it's possible, but I'm certain there must be a standard way of dealing with this. I have the following: template<typename FooBar, typename Foo> class Bar { private: Foo foo;
6
1937
by: PengYu.UT | last post by:
Hi, I have the following program which use a template as a template parameter. But it seems that it doesn't work. Do you know how to make it work? Although I can change the lines with comments the comments, but that is not what I want. Since the only different is for the program is either use "vector" "stack" ..., I don't want to specify redundant information "int" overthere.
3
3939
by: Chris | last post by:
I am having a very strange problem involving virtual functions in template classes. First of all, here is an extremely simplified structure of the two classes I am having problems with. template<class Type> class base { public: base& operator/=(const base&); Type *image;
6
2811
by: rincewind | last post by:
Hi, can anybody summarise all options for partial template specialization, for all kind of parameters (type, nontype, template)? I *think* I understand options for partial specialization on type parameters - in place of a template argument one can construct arbitrary valid C++ type declaration, more or less like in "typedef" statement. What about nontype parameters? Am I right that you cannot partially
2
1977
by: Greg Buchholz | last post by:
/* I've been experimenting with some generic/polytypic programs, and I've stumbled on to a problem that I can't quite figure out. In the program below, I'm trying to define a generic version of "transform" which works not only on lists, but lists of list, lists of lists of lists, etc. I'm calling it "fmap" and it passes around actual lists instead of iterators (for now). In order to get it to work, I thought I'd have one templated...
5
2538
by: Wayne Shu | last post by:
Hi, guys I am reading Vandevoorde and Josuttis 's "C++ Template The Complete Guide" these days. When I read the chapter 15: Traits and Policy classes. I copy the code in 15.2.2 that use to determining the class type. The code is below:
8
284
by: William Xu | last post by:
Compiling: template <class T = int> T foo(const T& t) {} int main(int argc, char *argv) {} gcc complains:
2
6642
by: Clyde | last post by:
Hi, what i'm trying to do is: /////////////// Code Start template <class TType, int* p = 0> class Template { public:
0
8991
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
9544
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...
0
9247
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
8243
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
6796
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
6074
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
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
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.