Question: How can I ensure that a specific method is called, at compile time?

For example, suppose I have an object with 2 methods:

```
struct Foo
{
   ... func1(...);
   ... func2(...);
};

```

and I want to ensure that func1 is called before any calls to func2, i.e.:

```
int main()
{
   Foo f;
   ...
   f.func1(...);
   f.func2(...);
   f.func2(...); // and so on
}

```

but I want to generate a compile error if I do something like that:

```
int main()
{
   Foo f;
   ...
   f.func2(...);  // generate a compile error due the fact that func1 must be called first
   f.func1(...);
   f.func2(...); // and so on
}

```

Answer: 
While curious why would you do this, general note is that you must ***expose to user an interface that cannot be used wrong***. Guts go private:

```
struct Foo
{
public:
    void callme()
    {
        func1();
        func2();
    }

private:
    ... func1(...);
    ... func2(...);

};

int main()
{
    Foo f;
    f.callme();
}

```

If you need to enforce one time initialization of objects, do it in constructor:

```
struct Foo
{
public:
    Foo()
    {
        func1();
    }

    func2(...);
private:
    ... func1(...);
};

int main()
{
    Foo f; // func1() called automagically
    f.func2();
}

```

Designing class interfaces, you must allways think about the worst things: users never read documentation, users always forget to call `foo.initialize()`, users always forget freeing memory and it leaks, etc.
I really do not suggest to do so, but if you need it for debugging purposes you can try following.
Change every call func1() to

```
#define FLAG
func1();

```

and func2() to

```
#ifdef FLAG
func2();
#else
#error func1 should be called first!
#endif

```

So you will receive a compile-time error if func2() will be mentioned upper in text then func1. It does not mean it will be really called earlier during execution.