|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
'function' : cannot convert parameter number from 'type1' to 'type2'
This snapshot is from Visual C++ 6.0
Any help ???????????????? ------------------------------------------------------------------------ #include <iostream> #include <queue> #include <list> using namespace std; int main() { int myint = 5; queue< list<int> > h; h.push(myint); //the following error is due to this line return 0; } ompiling... 1.cpp E:\1\1.cpp(13) : error C2664: 'push' : cannot convert parameter 1 from 'int' to 'const class std::list<int,class std::allocator<int> > &' Reason: cannot convert from 'int' to 'const class std::list<int,class std::allocator<int> >' No constructor could take the source type, or constructor overload resolution was ambiguous Error executing cl.exe. 1.obj - 1 error(s), 0 warning(s) |
|
#2
|
||||
|
||||
|
I haven't played with STL yet, but it looks like you created h as a queue of lists, so the queue's push method is expecting a list instead of the int that you are feeding it.
|
|
#3
|
|||
|
|||
|
The documentation of STL says that 'queue' class provides simpler interface by encapsulating 'list' class. i.e. its push() and pop() functions internally calls push_front() etc functions of list class.
We only have to supply the integer (or the type whose list is created). |
|
#4
|
||||
|
||||
|
Quote:
So then are you saying that you should have written your declaration as: queue<int> h; ? EDIT: In Google'ing on 'STL queue', I found this code fragment: Code:
list<int> myList;
for(int j=1;j<5;++j)myList.push_back(j);
queue<int, list<int> > myQueue(myList);
Would that queue declaration cover what you are trying to do? Last edited by dwise1_aol : June 16th, 2003 at 07:22 PM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > 'function' : cannot convert parameter number from 'type1' to 'type2' |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|