Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7819977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:08:20+00:00 2026-06-02T07:08:20+00:00

I am trying to define a vector < Queue >. this vector should contain

  • 0

I am trying to define a vector < Queue >. this vector should contain the starting address of each queue object. I have created a copy constructor and an assignment operator within the List.h (queue has private: list). However even before my program runs, it raises the error : List.h:156:1: error: invalid use of template-name ‘List’ without an argument list

Here is the code (arrowed out the relevant bits)

#ifndef LIST_H
#define LIST_H
#include "ListNode.h"

using namespace std;
template <typename NODETYPE>
class List {
public:
    List(const List&);                    <-----------copy constructor 
    List();
    ~List();
    void insertAtFront(const NODETYPE& );
    void insertAtBack (const NODETYPE& );
    bool removeFromFront(NODETYPE& );
    bool removeFromBack (NODETYPE& );
    bool isEmpty() const;
    void print() const;
    int length() const;
    List<NODETYPE>& operator=(const List&);     <----- assignment operator overload (see end)
private:
    ListNode<NODETYPE> *firstPtr;
    ListNode<NODETYPE> *lastPtr;
    ListNode<NODETYPE> *getNewNode (const NODETYPE& );
};

template <typename NODETYPE>                <------------code for copy constructor
List<NODETYPE>::List(const List& source){
    firstPtr = source.firstPtr;
    lastPtr = source.lastPtr;}


template <typename NODETYPE>
List<NODETYPE>::List():firstPtr(0),lastPtr(0){}

template <typename NODETYPE>
List<NODETYPE>::~List(){
    if (!isEmpty()){
        cout<<"\nDestroying node ... \n";
        ListNode<NODETYPE> *currentPtr = firstPtr;
        ListNode<NODETYPE> *tmpPtr;
        while (currentPtr != 0){
            tmpPtr = currentPtr;
            cout<<tmpPtr->value<<endl;
            currentPtr = currentPtr->nextPtr;
            delete tmpPtr;
        }
        }
    cout<<"\nAll node destroyed\n";
    }

template <typename NODETYPE>
void List<NODETYPE>::insertAtFront(const NODETYPE &val){
    ListNode<NODETYPE>*newPtr = getNewNode(val);
    if (isEmpty()){
        firstPtr = lastPtr = newPtr;}
    else {
        newPtr ->nextPtr = firstPtr;
        firstPtr = newPtr;                                          // do not understand this frag
    }}

template <typename NODETYPE>
void List<NODETYPE>::insertAtBack(const NODETYPE& val){
        ListNode<NODETYPE>*newPtr = getNewNode(val);
    if (isEmpty()){
        firstPtr = lastPtr = newPtr;}
    else {
        lastPtr ->nextPtr =newPtr;
        lastPtr = newPtr;                                           // do not understand this frag
    }

}

template <typename NODETYPE>
bool List<NODETYPE>::removeFromFront(NODETYPE& data)
{
    if (isEmpty()){
        return false;}
    else
    {
        ListNode<NODETYPE> *tempPtr = firstPtr;
        if (firstPtr == lastPtr)
            firstPtr = lastPtr = 0;
        else
            firstPtr = firstPtr->nextPtr;           // must look at detail inside DDD, what happens to the current ListNode object pointed to byfirstPtr
        data = tempPtr->value;
        delete tempPtr;
        return true;
    }
}
template <typename NODETYPE>
bool List<NODETYPE>::removeFromBack (NODETYPE& data) {

    if (isEmpty){
        return false;}
    else
    {
        ListNode<NODETYPE> *tempPtr = firstPtr;
        if (firstPtr == lastPtr)
            firstPtr = lastPtr = 0;
        else
        {
            ListNode<NODETYPE> *currentPtr = firstPtr;
            while (currentPtr->nextPtr !=lastPtr){
                currentPtr = currentPtr->nextPtr; }
            lastPtr = currentPtr;
            currentPtr ->nextPtr = 0;
        }
        data= tempPtr->value;
        delete tempPtr;
        return true;
    }
    }

template <typename NODETYPE>
bool List<NODETYPE>::isEmpty() const{                               // CONSTANT MEMBER FUNCTION
    return firstPtr==0;
    }

                                                                // different from textbook (see p 755)
template <typename NODETYPE>
ListNode<NODETYPE>* List<NODETYPE>::getNewNode(const NODETYPE&value) {
    return new ListNode <NODETYPE>(value); }



template<typename NODETYPE>
void List<NODETYPE>::print() const {
    if (isEmpty()) {
        cout<<" This list is empty\n";
        return ;}
    ListNode<NODETYPE> *currentPtr = firstPtr;
    while (currentPtr !=0)
    {
        cout << currentPtr->value <<' ';
        currentPtr = currentPtr->nextPtr;
        }
    cout<< "\n\n";

}

template <typename NODETYPE>
int List<NODETYPE>::length() const {
    if (this->isEmpty()){
        cout<< "\n Return size of what ? .. this list is empty ";
        return 0; }
    int size = 1;
    ListNode<NODETYPE>* currentPtr = firstPtr;
    while (currentPtr != lastPtr) {
        currentPtr = currentPtr->nextPtr;
        size +=1;
        }
    return size;
}

 template<typename NODETYPE>                       
List<NODETYPE>& List<NODETYPE>::operator=(List& rhs)       <---- line of error
{
    if (this !=&rhs){
        this->firstPtr = rhs.firstPtr;
        this->lastPtr = rhs.lastPtr; 
        return &firstPtr;
    }

   #endif

Calling program is as follows:

#include <iostream>List& operator=(const List&);
#include <vector>
#include "Queue.h"
#include <algorithm>
using namespace std;

int main () {
    vector < Queue <int> > dodo;
    for (int init = 0; init<4;init++ ){
        dodo.push_back(init);
    vector <Queue <int> >::const_iterator iterator;
    for (iterator = dodo.begin();iterator !=dodo.end();iterator ++){
        cout<<"Address of each queue item "<<dodo[]<<'\t'<<&dodo[];}
    int dequeueInteger;
    Queue <int> intQueue;
    cout <<"\n Size is .. " <<intQueue.howbig();
    cout << "\nProcessing integer Queue\n";
    for (int i=0;i<3;++i) {
        intQueue.enqueue(i);
        intQueue.printQueue(); }
    Queue<int> photo;
    photo = intQueue;

    cout <<"\n\n Here is mr. photo";
    photo.printQueue();

cout<<endl<<"\nSize of this queue is .. " <<intQueue.howbig();
cout<<endl;
while (!intQueue.isQueueEmpty()){
    intQueue.dequeue(dequeueInteger);
    cout<<dequeueInteger<<" dequeued\n";
    intQueue.printQueue();
}
}

file Queue.h

    #ifndef QUEUE_H
#define QUEUE_H
#include "List.h"

template <typename QUEUETYPE>
class Queue : private List< QUEUETYPE >
{
public:
void enqueue (const QUEUETYPE &data) {
    insertAtBack(data);}
bool dequeue (QUEUETYPE &data) {
    return removeFromFront(data); }
bool isQueueEmpty ()const {
    return this->isEmpty(); }
void printQueue() const {
    this ->print(); }
int howbig() const {
    return this->length();
    }


};
   #endif 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:08:21+00:00Added an answer on June 2, 2026 at 7:08 am

    You’re missing the template argument to the return value

    template<typename NODETYPE>                       
    List<NODETYPE>& List<NODTETYPE>::operator=(List& rhs)
        ^^^^^^^^^^
    

    You need that, because the compiler doesn’t know he’s parsing a List member, where List means the current template instantiation, until after List<NODETYPE>::.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to define a new type and have not had much luck finding
I have been trying to define multiple combo boxes in R using the tcltk
I am trying to add a user-defined plane object to a priority queue: int
I am trying to create a vector that contains pointers, each pointer points to
I am trying to define a vector of string in Visual C++ 2005 like
I'm trying to define the values of a 'row' or 1D vector and then
I have a main.cpp test.h and test.cpp> I am trying to pass my vector
Im trying to define a select tag in my view. My view looks like
I'm trying to define a delegate function that will return an IEnumerable. I'm having
I'm trying to define a new shortcode in WordPress, and I get the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.