Hi Everyone.
I am new to c++, and trying to complete an assignment. I have to create a class called 'Element', declare it in a header, implement it in a c++ file. When i try and compile it to object code (-c flag on g++), I get the following error:
g++ -c Element.cpp
Element.cpp:5: error: new types may not be defined in a return type
Element.cpp:5: error: return type specification for constructor invalid
here is the code for the .h:
and the .cpp:Code://Element.h an item implementation to hold any queue/stack data. #ifndef ELEMENT_H #define ELEMENT_H class Element{ public: Element(int* newItem); int* getItem(); void setNext(Element*); Element * getNext(); private: int * item; Element* next; } #endif
/all the research i have done on this compilation error points to the lack of a semi-colon after a struct... so I really dont know what im looking for. Any ideas on how to fix this?Code:/Element.cpp implementation to hold data element #include <stdio.h> #include "Element.h" Element::Element(int * newItem){ item = newItem; } int* Element::getItem(){ return item; } void Element::setNext(Element* newNext){ next = newNext; } Element* Element::getNext(){ return next; }
In addition, I later have to alter this class so it can store any type, not just 'int', using a template. Can anyone tell me where I can start looking to figure out how to do that?
Thanks