Item.h:
class Item { private: static const int price = 5; public: static const int& getPrice(); }; Item.cpp:
const int& Item::getPrice(){ return price; } main.cpp:
int main() { Item item; cout << item.getPrice() << endl; } Error: undefined reference to 'Item::price'
Why is this?
Item::getPrice()should work.static const int getPrice();?const int price = 5;it doesn't need to be astaticclass variable as far I can see.