3

I am have a problem with my Node class, I created the interface and implementation files of the class. When I build it, this error occurs: "error: redeclaration of 'Node::Node(const T&, Node, N ode)' may not have default arguments [-fpermissive] Node::Node(const T &item = T(), Node *nxt = NULL, Node *bck = NULL)".

My Interface

#ifndef NODE_HPP
#define NODE_HPP

#include <iostream> 
using namespace std;

template <typename T>
class Node {  
public:     
T item;     
Node<T> *next;  
Node<T> *back;  
Node(const T &item = T(), Node<T> *nxt = NULL, Node<T> *bck = NULL); };
#endif

and My implementation code

 #include "Node.hpp"
 template <typename T>
 Node<T>::Node(const T &item = T(), Node<T> *nxt = NULL, Node<T> *bck = NULL)
    {
        this->item = item;
        next = nxt;
        back = bck;
    }

SOLVED

I changed my implementation code like this and Solved.

#include "Node.hpp"
template <typename T>
Node<T>::Node(const T &item, Node<T> *nxt, Node<T> *bck)
{
    this->item = item;
    next = nxt;
    back = bck;
}
khayyam
  • 33
  • 1
  • 10
  • @paulsm4 thanks a lot.Solved – khayyam Nov 10 '18 at 23:58
  • The reason is that the default values are supplied at the call point, so the default values need to be visible where (in this case) a `Node` is being constructed. The definition of the constructor, if distinct from the constructor declaration in the class definition, is not visible at the call point. – Peter Nov 11 '18 at 00:04
  • @khayyam_islamzadeh: Glad it worked for you, and sorry somebody deleted my comment about putting your defaults in the *declaration* instead of the *definition*: https://stackoverflow.com/questions/32105975. It sounds like maybe you just chose to eliminate the defaults altogether. I'm definitely glad you got it resolved, and thank you for posting back your solution! – paulsm4 Nov 11 '18 at 00:24

0 Answers0