N
N
Neonoviiwolf2018-06-07 01:48:56
C++ / C#
Neonoviiwolf, 2018-06-07 01:48:56

For the first time I use klion, I don’t understand why namespace didn’t please him?

Good
Even Clion highlights a lot of things in red and I don’t understand what’s wrong
5b1864bf5a5f4260429801.jpeg

#include <iostream>
using namespace std;


template <namespace T>
class List
{
public:
  List();
  ~List();

  void push_back(T data);

private:
  template <namespace T>
  class Node {
  public:
    Node * pNext;
    T data;
    Node(T data = T(), Node * pNext = nullptr) {
      this->data = data;
      this->pNext = pNext;
    }
  };
  int SIZE;
  Node<T> *head;
};


template<namespace T>
List<T>::List()
{
  SIZE = 0;
  head = nullptr;
};
template<namespace T>
List<T>::~List()
{
};
template<namespace T>
void List<T>::push_back (T data)
{
};

int main() {
  
  system("pause");
  return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThirVondukr, 2018-06-07
@Neonoviiwolf

As I understand it, you are implementing a singly linked list, the problem is that you cannot pass namespace to the template, and why?
+ In the declaration of the Node class in the template, you have a duplicate variable T, which, in principle, you can not even specify, then the type of the data variable of the Node class will take the type specified by the List class. (I hope you understand this scribble)

#include <iostream>
using namespace std;


template <class T>
class List
{
public:
  List();
  ~List();

  void push_back(T data);

private:
  class Node {
  public:
    Node * pNext;
    T data;
    Node(T data = T(), Node * pNext = nullptr) {
      this->data = data;
      this->pNext = pNext;
    }
  };
  int SIZE;
  Node *head;
};


template<class T>
List<T>::List()
{
  SIZE = 0;
  head = nullptr;
};
template<class T>
List<T>::~List()
{
};
template<class T>
void List<T>::push_back (T data)
{
};

int main() {

  system("pause");
  return 0;
}

PS I hope that helped.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question