#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    9
    Rep Power
    0

    '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. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,173
    Rep Power
    2222
    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.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    9
    Rep Power
    0
    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).
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,173
    Rep Power
    2222
    Originally posted by shim
    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).
    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.

IMN logo majestic logo threadwatch logo seochat tools logo