Blab
Blab

Reputation: 153

error: invalid conversion from

So I have a node class:

template <typename Type>
class NodeType
{
    public:
    Type m_data;
    NodeType<Type> *mp_next;
    // note data goes uninitialized for default constructor
    // concept being Type's constructor would auto-init it for us
    NodeType() { mp_next = NULL; }
    NodeType(Type data) {m_data = data; mp_next = NULL;}
};

And I'm trying to make a new node like this:

NodeType<int> n1 = new NodeType<int>(5);

And the compiler is telling me:

SLTester.cpp:73:40: error: invalid conversion from ‘NodeType<int>*’ to ‘int’ [-fpermissive]
SingList.h:29:2: error:   initializing argument 1 of ‘NodeType<Type>::NodeType(Type) [with Type = int]’ [-fpermissive]

Can anyone help me figure out as to why this is happening and/or what am I actually supposed to do?

Upvotes: 1

Views: 1662

Answers (1)

billz
billz

Reputation: 45410

By defining NodeType<int> n1, n1 is not a pointer type,

update:

NodeType<int> n1 = new NodeType<int>(5);

to:

NodeType<int> n1{5};

Or

NodeType<int> n1(5);

Upvotes: 3

Related Questions