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 960065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:07:18+00:00 2026-05-16T01:07:18+00:00

I’m currently creating a circular doubly-linked list as exercise. The exercise is templating the

  • 0

I’m currently creating a circular doubly-linked list as exercise. The exercise is templating the damn thing, which is proving to be quite a pain. After many, many, many error-removals I get more errors. I’d laugh at that, but I’m quite tired and exhausted now.

Node.h

template<class T>
class Node
{
public:
    Node(T val) : data(val), next(0), prev(0) {}
    Node(T val, Node *next, Node *prev) : data(val), next(next), prev(prev) {}
    Node() : data(0), next(0), prev(0) {}
    ~Node()
    {}

    Node *next;
    Node *prev;
    T data;
};

.

LinkedList.h // Superclass

    #ifndef _LINKEDLIST_H_
#define _LINKEDLIST_H_

#include "Node.h"

enum Direction
{
    Forward,
    Backward
};

template<class T>
class LinkedList
{
public: 
    virtual void push_back(T data) = 0;
    virtual void push_front(T data) = 0;

    virtual void pop_back() = 0;
    virtual void pop_front() = 0;

    virtual void insert_before(T data, int index) = 0;
    virtual void insert_after(T data, int index) = 0;

    virtual void pop_before() = 0;
    virtual void pop_after() = 0;

    virtual void display(Direction direction = Forward) = 0;
    virtual int  length() const = 0;

    virtual T operator[](int index) = 0;
    virtual Node<T> *operator()(T data) = 0; 
};

#endif

.

CDLinkedList.h // Circular Doubly-Linked List

template<class T>
class CDLinkedList : public LinkedList<T>
{
public:
    /* Functions go here */
Node<T> *operator()(T data)
{
    Node<T> *temp = head;
    for( int i(0); 
          i < length()-1 && temp->data != data; 
          ++i, temp = temp->next )
        continue;

    if( temp->data == data )
        return temp;
    else
    {
        std::cerr << "Error: Element not found." << std::endl;
        return 0;
    }
}

void display(Direction direction = Forward)
{
    std::ostream_iterator<T> oIter(std::cout, " ");
    if( direction == Forward )
    {
        Node<T> *temp = head;
        for( int i(0); i < length(); ++i, temp = temp->next )
            oIter = temp->data;
    }
    else
    {
        Node<T> *temp = tail;
        for( int i(0); i < length(); ++i, temp = temp->prev )
            oIter = temp->data;
    }
}

.

#include <iostream>
#include <vector>

int main( int argc, char** argv )
{
    using std::cout;
    using std::endl;
    using std::cin;
    using std::string;

    CDLinkedList<std::string> list;
    list.push_back("Hello");
    list.push_back(",");
    list.push_back("World.");
    cout << "Displaying normally..." << endl;
    list.display();
    cout << "Displaying backwards..." << endl;
    list.display(::Direction::Backward);

    cin.get();
    return 0;
}

The templates work with int as input, but not with string, which is what I’m currently trying to get to work.

The last function Node *operator()(T data) is my current problem child. The error I get is:

error C2784: 'bool std::operator !=(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'std::string'

What’s wrong here?

  • 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-05-16T01:07:19+00:00Added an answer on May 16, 2026 at 1:07 am

    You are lacking the comparison operators for std::string. Try adding an

    #include <string>
    

    in your source file which holds main.

    Including <iostream> gives you a forward declaration of std::string. That’s because <iostream> allows you to do a lot of string operations (for instance, it allows you to convert a string from/to pretty much anything by using string streams). However this forward declaration does not give you any comparison operators. You need to include <string> for that.

    For what it’s worth, you could have minimized your test case to

    #include <iostream>
    
    bool f() {
        std::string a, b;
        return a != b;
    }
    

    to demonstrate this issue. This test case fails to compile for exactly the same reason, and including <string> makes it work.

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

Sidebar

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.