Can ceres solver and nlopt use the same model for least squares curve fitting?

I have a model setup that is working with NLopt, the setup consist of a baseModel (abstract base class for all derived models to take advantage of polymorphism), see below code example (the code is very long and these are the core functionalities):

class BaseModel
{
public:
    virtual double calculate(doubel x, std::vector<double>& params) const =0;
}

class Model1: public BaseModel
{
public:
    double calculate(doubel x, std::vector<double>& params) const override
    {
        //do calculation1
        return ans1;
    }
}

class Model2: public BaseModel
{
public:
    double calculate(doubel x, std::vector<double>& params) const override
    {
        //do calculation2
        return ans2;
    }
}

class ModelManager
{
    std::shared_ptr<BaseModel> createModel(std::string selectedModel)
    {
        if(selectedModel =="model1") return make_shared<Model1>();
        if(selectedModel =="model2") return make_shared<Model2>();
        .
        .
        .
        if(selectedModel =="modeln") return make_shared<Modeln>();
    }

    void setModel(std::string selectedModel)
    {
        Model_ptr = createModel(selectedModel);
    }

    double objectiveFunction(std::vector<double>& params, std::vector<double>& grad)
    {
        //return the sum of resuduals squared using xdata and ydata;
        double res=0;
        for (int i=0;i<xdata.size();i++)
        {
            double modelValue = model_ptr->calculate(xdata[i], params)
            double resid = ydata[i]-modelValue
            res += resid*resid;
        }
        return res;
    }
    void nlopt_optimize()
    {
        // run the nlopt optimize and return the best parameters with fitdata;
        // this is working very fine for me right now
    }

    void ceres_optimize()
    {
        // run the ceres optimize and return the best parameters with fitdata;
        // I want to add this to solve the same models
    }
private:
std::shared_ptr<BaseModel> model_ptr;
std::vector<double> xdata,ydata,fitdata,bestParams;

}

As I mentioned, the code for nlopt is working very fine, I want to add the option to curve fit using ceres solver, so the user will set the model at runtime, by choosing the fitting model, the program and based on the model selection will fill all the fitting requirements like the number of parameters and their bounds, the problem arises when I attempted to add a CostFunctor that point to the model, it says that the model can not accept the template type sent by the functor, I tried to use templates in the baseModel but I could not due to pure virtual methode ‘calculate’.

Is there a way that I can preserve my working nlopt structure and add ceres solver functionnalities to it so it solves the same model without breaking the working code.

As troubleshooting, I searched the documentation of ceres solver, I checked the common questions asked about the subject in stackoverflow especially those of Sameer Agrawal the developer of ceres, and tried the template appraoch without success. I confirm that I reviewed all the suggested question during the editing of this question. I can provide more information as needed.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật