If you define something in a header, then it will be defined in every translation unit that includes that header - in your case, both AccountHandler
and main
. You should declare it in a header (if it needs to be accessed from multiple units), and define it in just one source file.
Assuming that it's a static class member (I'm having to guess, since you forgot to show us the code), you want something like:
// header
class AccountHandler
{
public:
static size_t number_of_account; // declaration
// other members...
};
// source file
size_t AccountHandler::number_of_account; // definition
Presumably, in your code, that definition is in the header.
That's assuming it's supposed to be static at all; that it's independent of any particular account (e.g. it represents the number of accounts that exist), rather than being associated with each account (e.g. it represents an account number). If it's not supposed to be static, then make sure it's not declared static
.
Include guards won't help with this; they prevent the header from being included more than once in each translation unit, but still allow them to be included from multiple units.