A
aiooua
Any idea why the following code does not compile?
----
#include<iostream>
#include<list>
using namespace std;
class Base {
public:
int val;
Base(int i):val(i){}
void show(){cout<<name()<<val<<endl;}
virtual string name() = 0;
};
class A: public Base{
public:
A(int i):Base(i){}
string name() { return "a";}
};
class B: public Base{
public:
B(int i):Base(i){}
string name() { return "b";}
};
typedef list<A*>::iterator a_iter;
typedef list<B*>::iterator b_iter;
typedef pair<a_iter,a_iter> a_seq;
typedef pair<b_iter,b_iter> b_seq;
template <class T> Base* show(pair<typename list<T*>::iterator,
typename list<T*>::iterator> seq, int val){
for(typename list<T*>::iterator i = seq.first; i!=seq.second; ++i)
if(i->val==val) i->show();
}
int main(){
list<A*> a_list;
list<B*> b_list;
for(int i=0;i<10;i++){
a_list.push_back(new A(i));
b_list.push_back(new B(i));
}
a_seq a = make_pair(a_list.begin(),a_list.end());
b_seq b = make_pair(b_list.begin(),b_list.end());
show(a, 5);
show(b, 6);
}
---
I get the following compilation errors.
---
test.cpp: In function `int main()':
test.cpp:43: no matching function for call to `show(a_seq&, int)'
test.cpp:44: no matching function for call to `show(b_seq&, int)'
--
both a_seq and b_seq are typedefed to pairs of list iterator. am i
missing something?
thanks,
----
#include<iostream>
#include<list>
using namespace std;
class Base {
public:
int val;
Base(int i):val(i){}
void show(){cout<<name()<<val<<endl;}
virtual string name() = 0;
};
class A: public Base{
public:
A(int i):Base(i){}
string name() { return "a";}
};
class B: public Base{
public:
B(int i):Base(i){}
string name() { return "b";}
};
typedef list<A*>::iterator a_iter;
typedef list<B*>::iterator b_iter;
typedef pair<a_iter,a_iter> a_seq;
typedef pair<b_iter,b_iter> b_seq;
template <class T> Base* show(pair<typename list<T*>::iterator,
typename list<T*>::iterator> seq, int val){
for(typename list<T*>::iterator i = seq.first; i!=seq.second; ++i)
if(i->val==val) i->show();
}
int main(){
list<A*> a_list;
list<B*> b_list;
for(int i=0;i<10;i++){
a_list.push_back(new A(i));
b_list.push_back(new B(i));
}
a_seq a = make_pair(a_list.begin(),a_list.end());
b_seq b = make_pair(b_list.begin(),b_list.end());
show(a, 5);
show(b, 6);
}
---
I get the following compilation errors.
---
test.cpp: In function `int main()':
test.cpp:43: no matching function for call to `show(a_seq&, int)'
test.cpp:44: no matching function for call to `show(b_seq&, int)'
--
both a_seq and b_seq are typedefed to pairs of list iterator. am i
missing something?
thanks,