How to correctly declare a static variable in this context?
#include <iostream> using namespace std; struct link { int data; link *next; }; class some { private: static link *first; public: some(int d) { link *newlink = new link; newlink->data = d; newlink->next = first; first = newlink; } void Show() { link *current = first; while(current) { cout << current->data << endl; current = current->next; } } }; link some::first = nullptr; int main() { some ob1(1), ob2(2), ob3(3); ob3.Show(); return 0; } Errors:
conflicting declaration 'link some :: first' link some :: first = nullptr;
previous declaration as 'link * some :: first' static link * first;
some :: first is not defined [-fpermissive] link some :: first = nullptr;