c++ - Missing type specifier On a Templated List Class using Templated Nodes -


this contents of graph.h without header protects , other functions

template <class t> class node{ public:     t data;     node<t> *nextnode; public:     node();     node(t a);     t getvalue();     void setvalue(t a);     void chainnode(node<t> a);     void chainnode(node<t> *a);     node<t> getnextnode();     void unchainnode(); }; //related methods template <class t> node<t>::node(){     data = null;     nextnode = null; }     template <class t> void node<t>::chainnode(node<t> a){     nextnode = null;     nextnode = &a; } template <class t> void node<t>::chainnode(node<t> *a){     nextnode = null;     nextnode = a; }      template <class t> class list{ public:     node<t> *head;     list(node<t> a);     void addinfront(node<t> a);     void addinfront(node<t> *a);     void append(node<t> a);     bool remove(node<t> a);     bool remove(t a);     bool contains(t a);     bool deletelist(); }; //only working method of list template <class t> list<t>::list(node<t> a){ head = &a; } // error occurs in function template <class t> list<t>::addinfront(node<t> a){     a.chainnode(head);     head = null;     head = &a; }         

and main

#include<iostream> #include"graph.h" int main(){     node<int> = node<int>(20);     list<int> d = list<int>(a);     node<int> b = node<int>(20);     d.addinfront(b); } 

and here error

error c4430: missing type specifier - int assumed . note: c++ not support default-  int 

my compiler (msvs 11) tells me have c4430 error @ end of addinfront function , end mean saying line end curly bracket has error.i have tried every thing under moon try rid of error can't seem fix it.

you forgot specify return type in definition of addinfront() function:

template <class t> void list<t>::addinfront(node<t> a) { //                 ^^^^ //                 missing     a.chainnode(head);     head = nullptr;     head = &a; } 

also notice, copy-initializations belows:

node<int> = node<int>(20); list<int> d = list<int>(a); node<int> b = node<int>(20); 

are unnecessary. rather use direct initialization:

node<int> a(20); list<int> d(a); node<int> b(20); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -