-2
/*Process.h*/
class Process  {
    public:
    Process(ProcessID thirdParty_pid);

    protected:
    void createImpl();

    private:
    ProcessImpl  * _impl;
};


/*ProcessImpl.h*/

 class ProcessImpl {
      public :
      ProcessImpl(ProcessID thirdParty_pid);
 }

Using PIMPL idiom now I amtrying to invoke ProcessImpl constructor in this way:

Process::Process(ldframework::ProcessID tpid):_impl(ldframework::ProcessImpl::ProcessImpl(tpid)) {
}

But I am getting following error error: cannot convert ProcessImpl to ProcessImpl* in initialization

pls help in resolving this error and also let me know wts the correct metrhod to invoke

Dallas
  • 17,186
  • 21
  • 64
  • 82
user2380779
  • 11
  • 1
  • 5

3 Answers3

1

Since _impl is a pointer, you have to initialize it with a pointer:

Process::Process(ldframework::ProcessID tpid)
    : _impl(new ldframework::ProcessImpl::ProcessImpl(tpid))
{ ... }

Note the use of the new keyword in the initialization of _impl.

Some programmer dude
  • 363,249
  • 31
  • 351
  • 550
1

_impl is a pointer (PIMPL => Pointer to Implementation).

So, use the new keyword for initialization.

Process::Process(ldframework::ProcessID tpid)
  :_impl( new ldframework::ProcessImpl::ProcessImpl(tpid)) {
}

But use PIMPL with smart_pointers, therefore, read Sutter about compilation firewalls!

Kai Walz
  • 756
  • 1
  • 5
  • 15
0

Your expression ldframework::ProcessImpl::ProcessImpl(tpid) evaluates to type ProcessImpl, which is not the same as type ProcessImpl*, the type of your member _impl.

Try using new inside your initializer list instead, and remember delete in your destructor.

e.g.

: _impl( new ldframework::ProcessImpl::ProcessImpl(tpid) )

and later in your destructor

delete _impl;
DuckMaestro
  • 13,332
  • 9
  • 61
  • 83