C++ 超载<&书信电报;C++;

C++ 超载<&书信电报;C++;,c++,C++,我正在尝试重载ok,因此正如注释所示,我需要从操作符返回一些内容,如 DLList & DLList::operator << (const int value ) { insert_first(value); return *this; } DLList&DLList::operator您没有从operator返回任何内容您没有返回*这的意思是operator现在我看到了,谢谢您为什么“insert_first”实际上是在head之后插入它?这就是它的编写方式。hea

我正在尝试重载
ok,因此正如注释所示,我需要从操作符返回一些内容,如

DLList & DLList::operator << (const int value ) 
{
insert_first(value);
return *this; 
}

DLList&DLList::operator您没有从
operator返回任何内容您没有返回
*这
的意思是
operator现在我看到了,谢谢您为什么“insert_first”实际上是在
head
之后插入它?这就是它的编写方式。head不存储值,它只是为了方便。
#ifndef DLLIST_H
#define DLLISH_H

#include <stdio.h>
#include <iostream>

class ListNode {
public:
    int value; 

    ListNode * next;
    ListNode * prev;

    static int node_count;

    ListNode() {
        node_count++;
    }

    ~ListNode() {
        node_count--;
    }

    static void print_node_count() {
        std::cout << "Node Count: " << node_count << std::endl;
    }
};

class DLList {
private:
    ListNode * head;
public:
    DLList();
    ~DLList();

    void print_list();
    void print_list( std::string list_name );
    void insert_first( int value );

    bool remove( int value );
    void concat_list( DLList * list_to_add );

    DLList & operator << (const int value );
};
void DLList::insert_first( int value ) 
{
    ListNode * n = new ListNode();

    n->value = value;
    n->next = head->next;
    n->prev = head;

    head->next = n;
    n->next->prev = n;    
}
DLList & DLList::operator << (const int value ) 
{
insert_first(value);
return *this; 
}