Search code examples
c++boostshared-ptrsmart-pointers

Simple boost smart pointer syntax issue


When using either boost::scoped_ptr or boost::shared_ptr I get the error

1>*\algomanager.cpp(28) : error C2064: term does not evaluate to a function taking 1 arguments

I have code like this . . .

class X{
  boost::shared_ptr<cPreFilterProcess> preProcess;
public:
  X(){
    preProcess(new cPreFilterProcess(pars));
  }
};

What am I missing? Thanks.


Solution

  • My mythical glass orb of magic debugging tells me you're doing something like this:

    class X{
      boost::shared_ptr<cPreFilterProcess> preProcess;
    public:
      X(){
        preProcess(new cPreFilterProcess(pars));
      }
    };
    

    You need to use either the member initializer like:

    X() : preProcess(...){}
    

    Or use .reset since your can't just assign a pointer like that:

    X() { preProcess.reset(...); }
    

    I would strongly recommend the first option though.