Help needed on "no match function error"

Discussion in 'C++' started by Jolie Chen, Jun 24, 2008.

  1. Jolie Chen

    Jolie Chen Guest

    I am learning template programming now, and I wrote the following code

    #include <iostream>
    #include "Queue.h"
    using namespace std;

    template <typename T> class QueueItem
    {
    public:
    QueueItem(T item):value(item),next(0){}
    T value;
    QueueItem *next;
    };

    template <typename T> class Queue
    {
    private:
    QueueItem<T> *head;
    QueueItem<T> *tail;
    public:
    Queue():head(0),tail(0){}
    Queue(const Queue &orig):head(0),tail(0)
    {
    for(QueueItem<T> *temp=orig.head;temp;temp=temp->next)
    {
    push(temp->value);
    }

    }
    Queue& operator=(Queue& orig)
    {
    head =0;
    tail =0;
    for(QueueItem<T> *temp=orig.head;temp;temp=temp->next)
    {
    push(temp->value);
    }
    return *this;
    }


    ~Queue()
    {
    while (head)
    {
    cout<<"In~Queue";
    pop();
    }
    }
    void pop();
    void push(T item);
    bool empty(){
    if (head==0)
    return 1;
    return 0;
    }

    };



    template <typename T> void Queue<T>::push(T item)
    {
    if(empty())
    {
    head = new QueueItem<T>(item);
    tail=head;
    }
    else
    {
    QueueItem<T> *temp;
    temp = new QueueItem<T>(item);
    tail->next=temp;
    tail=temp;
    }
    }



    template <typename T> void Queue<T>::pop()
    {
    if(!empty())
    {
    QueueItem<T> *temp;
    temp=head;
    head = head->next;
    cout<< "pop a value of "<<temp->value<<endl;
    delete temp;
    }
    else
    {
    cerr<<"the Queue is empty, so cannot call pop function"<<endl;
    }
    }



    int main()
    {
    Queue<int> orig_queue;
    for(int i=0; i<8; i++)
    orig_queue.push(i);

    Queue<int> copy_queue;
    copy_queue(orig_queue);//this line has compile error
    return 0;
    }

    and get the compiling error :
    no match for call to ‘(Queue<int>) (Queue<int>&)’ Queue Queue.cc line
    103 1214317008414 99

    for the line copy_queue(orig_queue): line

    Could you please help me out for this problem? Thanks
    Jolie Chen, Jun 24, 2008
    #1
    1. Advertising

  2. Jolie Chen

    Jolie Chen Guest

    Victor,

    You are right. Thank you so much.

    Jolie

    On Jun 24, 9:48 am, Victor Bazarov <> wrote:
    > Jolie Chen wrote:
    > > I am learning template programming now, and I wrote the following code

    >
    > > #include <iostream>
    > > #include "Queue.h"
    > > using namespace std;

    >
    > > template <typename T> class QueueItem
    > > {
    > > public:
    > >    QueueItem(T item):value(item),next(0){}
    > >    T value;
    > >    QueueItem *next;
    > > };

    >
    > > template <typename T> class Queue
    > > {
    > > private:
    > >    QueueItem<T> *head;
    > >    QueueItem<T> *tail;
    > > public:
    > >    Queue():head(0),tail(0){}
    > >    Queue(const Queue &orig):head(0),tail(0)
    > >    {
    > >            for(QueueItem<T> *temp=orig.head;temp;temp=temp->next)
    > >            {
    > >                    push(temp->value);
    > >            }

    >
    > >    }
    > >    Queue& operator=(Queue& orig)
    > >    {
    > >            head =0;
    > >            tail =0;
    > >            for(QueueItem<T> *temp=orig.head;temp;temp=temp->next)
    > >            {
    > >                    push(temp->value);
    > >            }
    > >            return *this;
    > >    }

    >
    > >    ~Queue()
    > >    {
    > >            while (head)
    > >            {
    > >                    cout<<"In~Queue";
    > >                    pop();
    > >                    }
    > >    }
    > >    void pop();
    > >    void push(T item);
    > >    bool empty(){
    > >            if (head==0)
    > >                    return 1;
    > >            return 0;
    > >    }

    >
    > > };

    >
    > > template <typename T> void Queue<T>::push(T item)
    > > {
    > >    if(empty())
    > >    {
    > >            head = new QueueItem<T>(item);
    > >            tail=head;
    > >    }
    > >    else
    > >    {
    > >            QueueItem<T> *temp;
    > >            temp = new QueueItem<T>(item);
    > >            tail->next=temp;
    > >            tail=temp;
    > >    }
    > > }

    >
    > > template <typename T> void Queue<T>::pop()
    > > {
    > >    if(!empty())
    > >    {
    > >            QueueItem<T> *temp;
    > >            temp=head;
    > >            head = head->next;
    > >            cout<< "pop a value of "<<temp->value<<endl;
    > >            delete temp;
    > >    }
    > >    else
    > >    {
    > >            cerr<<"the Queue is empty, so cannot call pop function"<<endl;
    > >    }
    > > }

    >
    > > int main()
    > > {
    > >    Queue<int> orig_queue;
    > >    for(int i=0; i<8; i++)
    > >            orig_queue.push(i);

    >
    > >    Queue<int> copy_queue;
    > >    copy_queue(orig_queue);//this line has compile error

    >
    > This syntax actually means to invoke the [non-existent] operator() for
    > the object called 'copy_queue' with 'orig_queue' as argument.  Did you
    > actually mean to do
    >
    >      Queue<int> copy_queue(orig_queue);
    >
    > ?
    >
    > >    return 0;
    > > }

    >
    > > and get the compiling error :
    > > no match for call to ‘(Queue<int>) (Queue<int>&)’      Queue   Queue.cc        line
    > > 103        1214317008414   99

    >
    > > for the line copy_queue(orig_queue): line

    >
    > > Could you please help me out for this problem? Thanks

    >
    > V
    > --
    > Please remove capital 'A's when replying by e-mail
    > I do not respond to top-posted replies, please don't ask
    Jolie Chen, Jun 24, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. andy

    urgent help needed !

    andy, Jul 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    905
  2. Thomas Nick
    Replies:
    0
    Views:
    1,864
    Thomas Nick
    Jun 13, 2005
  3. Ryan Macy

    Ideas needed & help needed!

    Ryan Macy, Jul 19, 2006, in forum: Ruby
    Replies:
    2
    Views:
    493
    Ryan Macy
    Jul 19, 2006
  4. LeTubs
    Replies:
    6
    Views:
    114
    Tad McClellan
    Jan 25, 2004
  5. John Farold
    Replies:
    0
    Views:
    378
    John Farold
    Aug 29, 2012
Loading...

Share This Page