Visual Studio 2015 "non-standard syntax; use '&' to create a pointer to member"
22,222
You're trying to return the member function value
, not the member variable data
. Change
const T& value() const { return value; }
to
const T& value() const { return data; }
Author by
Lawrence Aiello
Updated on July 21, 2022Comments
-
Lawrence Aiello almost 2 years
I am attempting my own Linked List implementation in C++ and cannot for the life of me figure out why I am having this error. I know there is an STL implementation but for reasons I am trying my own. Here is the code:
#include <iostream> template <class T> class ListElement { public: ListElement(const T &value) : next(NULL), data(value) {} ~ListElement() {} ListElement *getNext() { return next; } const T& value() const { return value; } void setNext(ListElement *elem) { next = elem; } void setValue(const T& value) { data = value; } private: ListElement* next; T data; }; int main() { ListElement<int> *node = new ListElement<int>(5); node->setValue(6); std::cout << node->value(); // ERROR return 0; }
On the specified line, I get the error "non-standard syntax; use '&' to create a pointer to member". What the hell does this mean?
-
songyuanyao over 8 years@LawrenceAiello Good luck. :)