473,699 Members | 2,367 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 2005
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
6271
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
11363
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
2728
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
1933
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
3936
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
2807
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
1975
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
2534
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
6637
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
8615
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
9174
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
9034
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
8914
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
8883
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
7750
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
4376
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...
0
4629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2009
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.