特定のコンストラクタを使用して作成されたオブジェクトの数をカウントします。私はC#
のような言語でこれをやっています。その前にコンストラクタでインクリメントしている変数static int
を作成しました。C++静的変数宣言不自然なリンカーエラー
私はあなたのコードを表示する前に - ここcompilementエラーです:
#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;
}
};
私は、この行を含めていた場合compilementエラーがoccurrs:
ここSeverity Code Description Project File Line Suppression State Error LNK2001 unresolved external symbol "private: static int Bill::count_of_created_bills" ([email protected]@@0HA) Ausgabenverwaltung c:\Users\xy\documents\visual studio 2017\Projects\Ausgabenverwaltung\Ausgabenverwaltung\Ausgabenverwaltung.obj 1
コードです
Bill b(1, 2, 3);