• B правой части каждого сообщения есть стрелки и . Не стесняйтесь оценивать ответы. Чтобы автору вопроса закрыть свой тикет, надо выбрать лучший ответ. Просто нажмите значок в правой части сообщения.

  • Познакомьтесь с пентестом веб-приложений на практике в нашем новом бесплатном курсе

    «Анализ защищенности веб-приложений»

    🔥 Записаться бесплатно!

  • CTF с учебными материалами Codeby Games

    Обучение кибербезопасности в игровой форме. Более 200 заданий по Active Directory, OSINT, PWN, Веб, Стеганографии, Реверс-инжинирингу, Форензике и Криптографии. Школа CTF с бесплатными курсами по всем категориям.

Template Single Linked Class

  • Автор темы DavidZizu
  • Дата начала
D

DavidZizu

Выдаёт ошибку, не компилируется (для упрощения сначала сделал без класса итератора).
Компилятор Visual Studio 2013.

Вот сам код:
Для header.h

//Single linked Linear List
#ifndef STL_List_H
#define STL_List_H

#include <iostream>
#include <string>

using std::cout;
using std::endl;

template<class Object>
class List;

template<class Object>
struct Node
{
public:
//actual data of Node
Object data;
//pointer to the next node
Node *next;
public:
//default constructor of class Node
Node()
{
data = NULL;
next = NULL;
}
/*
Node(Object input_data, Node *pointer1)
{
data = input_data;
next = pointer1;
}*/

//Accessors
Node *getPointer() const { return next; }
int getData() const { return data; }

//Mutators
void setPointer(Node input) { next = input; }
void setData(int data1) { data = data1; }
};

template<class Object>
class List
{
private:
Node<Object> *beginning;
public:
//typedef iterator<Object> itr;
List()
{
beginning->data = NULL;
beginning->next = NULL;
}

void AddToEnd(Object input)
{
if ((beginning->next == NULL) && (beginning->data == NULL))
beginning->data = input;
else
{
Node<Object> *temp;
temp = beginning->next;
while (temp->next != NULL)
temp = temp->next;
Node<Object> *new_one = new Node<Object>();
temp->next = new_one;
new_one->data = input;
new_one->next = NULL;
}
}
/*
void RemoveFromEnd()
{
Node *temp;
temp = beginning->next;
while (temp->next != NULL)
temp = temp->next;
delete temp;
return 0;
}

Node<Object> searchList(Object input)
{
Node *temp;
temp = beginning->next;
while (temp->next != NULL)
temp = temp->next;
return temp;
}*/

void display()
{
Node<Object> *temp;
temp = beginning->next;
while (temp->next != NULL)
{
temp = temp->next;
cout << temp->data;
}
}
};
#endif


И для test.cpp

#include "STL_List.h"
#include <string>
#include <iostream>
#include "STL_List.h"

using std::cout;
using std::endl;

int main()
{
List<int> l1;

cout << "ddd";

l1.AddToEnd(10);
}

Заранее спасибо
 

Вложения

  • NewOne.png
    NewOne.png
    13,2 КБ · Просмотры: 258
R

rrrFer

Поставь breakpoint, запусти отладку, узнай на какой строчке программа падает.
 
Мы в соцсетях:

Обучение наступательной кибербезопасности в игровой форме. Начать игру!