Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Why is this code giving me so many errors? My professor gave me this code and sa

ID: 3910525 • Letter: W

Question

Why is this code giving me so many errors? My professor gave me this code and says it works on his computer but it gives me errors on mine

#ifndef LL_H

#define LL_H

#include <iostream>

// A template class takes in a type in the <>. Look at how we declare a vector

// with: vector<int> thing, there the <int> is the template type.

template <typename T> class LinkedList {

private:

   // private struct for the LL

   struct Node {

       T data;

       Node* next;

       Node* prev;

       Node(): // <- this is called an initializer list, the most common

               // way to write constructors since C++11

           data { T{} },

           next {nullptr},

           prev {nullptr} {};

       explicit Node(const T & _dataMember): // <- the explicit means we

               // can't pass in any extra values to this function or do

               // implicit type casting – important only because this is

               // allowed in C

           data {_dataMember},

           next {nullptr},

           prev {nullptr} {};

       explicit Node(const T && _dataMember):

           data {_dataMember},

           next {nullptr},

           prev {nullptr} {};

   };

Explanation / Answer

Please find below the correct code.

CODE

=============

#include <iostream>

#ifndef LL_H

#define LL_H

// A template class takes in a type in the <>. Look at how we declare a vector

// with: vector<int> thing, there the <int> is the template type.

template <typename T> class LinkedList {

private:

// private struct for the LL

struct Node {

T data;

Node* next;

Node* prev;

Node(): // <- this is called an initializer list, the most common

// way to write constructors since C++11

data { T{} },

next {nullptr},

prev {nullptr} {};

explicit Node(const T & _dataMember): // <- the explicit means we

// can't pass in any extra values to this function or do

// implicit type casting – important only because this is

// allowed in C

data {_dataMember},

next {nullptr},

prev {nullptr} {};

explicit Node(const T && _dataMember):

data {_dataMember},

next {nullptr},

prev {nullptr} {};

};

};

#endif

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote