I am new to C++ and when I try to run this program it tells me: "error LNK2001: unresolved external symbol "private: static int Plate::plate_nID". I am right now just trying to create the plate class and print out the ID. Not sure where I went wrong.
#pragma once
#include <string>
using namespace std;
class Plate{
private:
int id;
string plateName;
static int plate_nID;
int generateID(){
plate_nID++;
return plate_nID;
}
public:
Plate(string name){
plateName = name;
id = generateID();
}
~Plate(){}
int getID(){
return id;
}
string getName(){
return plateName;
}
};
Here is my main:
#include "Plate.cpp"
#include "PlateNode.cpp"
using namespace std;
int main(){
Plate s=Plate::Plate("p1");
cout << s.getID();}
I have looked at this question: Undefined reference to static class member which similar questions to mine were marked as dulpicates of, but I when I try to do that it tells me: cannot instantiate non-static member outside of class. Please Help!