Question: For example, if I have a class like this:

```
class Widget {
public:
  virtual void Init(); // In this function, call some virtual function
                       // to construct the object
  void Paint();        // Deprecated, use paintWidget instead
  void PaintWidget();  // A new implementation of paint

  ...                  // Other stuff, including a virtual function
                       // which need to be called to construct the object
}

```

The construction of a `Widget` requires a virtual function call (that's why I wrote the `Widget::Init()`). Is there a way to make a constraint on `Widget::Init()` so that it must be called before any use of the object, and raise error if the user violates the constraint? Another problem is creating a customize warning message for a deprecated method. With the code above, if a user of my class calls `Widget::paint()`, how can I tell them to use `Widget::paintWidget()` instead of deprecated `Widget::paint()`, and tell them about the consequence of using the deprecated one? Thank you.

Answer: 
Part 1 of your question:
------------------------

No, there is no good way of giving a custom message on using a private method. What I would do is to make sure that you only have a public API which forwards to the private implementation. This can be done via some pimple pattern or by creating a facade.

As you did not specify the way someone would get the Widget, I'm currently assuming a Singleton.

```
class Widget {
public:
    Widget() : _impl(getHoldOfPrivateWidgetViaSingleton())
    {
         _impl.init();
    }
    // ...
private:
    PrivateWidget &_impl;
};

// Note: rename of the Widget in your example
class PrivateWidget {
private:
    friend class Widget;
    PrivateWidget();
    // ...
};

```

The disadvantage of doing this is that you will have to write some/a lot of forwarding code. 

Part 2 of your question:
------------------------

```
class Widget {
public:
  void Init();
  [[deprecated("use paintWidget instead")]] void Paint();
  void PaintWidget(); // A new implementation of paint
  ...
private:
  Widget();
  ...
}

```

Note that if you don't have access to a modern compiler with C++17 enabled, you might want to check out your compiler specific attributes.
You can use **#warning** directive, most of the widespread compilers (GCC, VC, Intels and Mac), support #warning message.

```
#warning "this is deprecated, use the Init() method instead"

```

A good practive is to not only show a warning (which people can ignore), but make the compiling fail, using the #error directive (which is quite standard):

```
#  error "this method is forbidden and private"

```

As a Visual Studio specific [solution](https://stackoverflow.com/a/2143358/2183287), you can use *pragma*.