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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.