mardi 23 février 2016

Forbid code to compile if some function is not called

Is there a way in C++ to forbid code to compile if the specific function was not called.

Imagine I have some class:

class CExample
{
public:
    void Init();
    void DoWork();

};

Is there a way to forbid calling DoWork() if the Init() function was not called for class object?

I want to forbid writing such a code:

CExample e;
e.DoWork();

and permit this version:

CExample e;
e.Init();
e.DoWork();

Can I reach this behaviour somehow with metaprogramming?

Aucun commentaire:

Enregistrer un commentaire