473,385 Members | 1,317 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,385 software developers and data experts.

template argument to a template class

I am unable to figure out how to instantiate class temp below.
"temp<int, b<int, int> >" causes error:
error: type/value mismatch at argument 2 in template parameter
list for `template<class T, template<int <anonymous>, int
<anonymous> >
class T2> class temp'

/************************************************** ********************************************/
#include<iostream>
using namespace std;

template<class T, template<int, int>class T2>
class temp
{
T val;
public:
void print()
{
cout<<val;
}
};

class a
{
};

template<class T1, class T2>
class b
{
};

template<class
void method(temp<int, b<int, int> > li,temp<a, b<int,int> > la)
{
li.print();
}

int main()
{

temp<int, b<int, int> > ti;
temp<a, b<int, int> > ta;

method(ti, ta);

return 0;
}
/************************************************** ********************************************/

Dec 29 '05 #1
2 1393
please ignore incomplete statement "template<class" just before
definition of method(). It was a copy-paste error.

Dec 29 '05 #2
wrote in news:11**********************@g44g2000cwa.googlegr oups.com in
comp.lang.c++:
I am unable to figure out how to instantiate class temp below.
"temp<int, b<int, int> >" causes error:
error: type/value mismatch at argument 2 in template parameter
list for `template<class T, template<int <anonymous>, int
<anonymous> >
class T2> class temp'

/************************************************** ********************
************************/ #include<iostream>
using namespace std;

template<class T, template<int, int>class T2>
class temp
{
T val;
public:
void print()
{
cout<<val;
}
};

class a
{
};

template<class T1, class T2>
class b
{
};

You need 'b' to have 'int' arguments not 'class', something like:

template <int A, int B >
class b
{
};
template<class
void method(temp<int, b<int, int> > li,temp<a, b<int,int> > la)
{
li.print();
}

int main()
{

temp<int, b<int, int> > ti;
Would become:
temp< int, b<1, 2> > t_int_1_2;
temp<a, b<int, int> > ta;

method(ti, ta);

return 0;
}


Alternitively change you defenition of 'temp':

template < typename T, template < typename T1, typename T2 > class C >
class temp
{
};

Now 'temp' will work with your original defenition of 'b':

temp< int, b< int, int > > ti;

Depends what you wan't to do.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Dec 29 '05 #3

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

Similar topics

2
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,...
8
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...
3
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...
6
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...
3
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. ...
6
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...
2
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...
5
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...
8
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
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.