I want to count the ammount of objects which have been created by using a certain constructor. I have done this in languages like C#
before so I created a static int
variable which I'm incrementing in the constructor.
Before I show you the code - here is the compilement error:
Severity Code Description Project File Line Suppression State Error LNK2001 unresolved external symbol "private: static int Bill::count_of_created_bills" (?count_of_created_bills@Bill@@0HA) Ausgabenverwaltung c:\Users\xy\documents\visual studio 2017\Projects\Ausgabenverwaltung\Ausgabenverwaltung\Ausgabenverwaltung.obj 1
Here is the code:
#pragma once
class Bill
{
private:
static int count_of_created_bills;
int id; // Unique Identification
double ammount; // Ammount of bill
int month; // Month of bill (January = 0, February = 1 ...)
int type_of_spending; // Type of spending (Food = 0 ...)
public:
Bill(int a, int m, int t):ammount(a), month(m), type_of_spending(t)
{
count_of_created_bills++;
id = count_of_created_bills;
}
};
The compilement error occurrs if I'm including this line:
Bill b(1, 2, 3);