Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5838893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:31:00+00:00 2026-05-22T11:31:00+00:00

I have multiple class derivated from A class A : public boost::enable_shared_from_this<A> { public:

  • 0

I have multiple class derivated from A

class A : public boost::enable_shared_from_this<A> {
    public:
        typedef boost::shared_ptr<A>    pointer;

        static pointer create(tcp::socket& socket) {
            return pointer(new A(socket));
        }
    private:
        A(&tcp::socket socket) : m_socket(socket) {}

        tcp::socket&    m_socket;
}

Class Aa : public A {
    public:
        typedef boost::shared_ptr<Aa>   pointer;

        static pointer create(tcp::socket& socket) {
            return pointer(new Aa(socket));
        }

    private:
        Aa(&tcp::socket socket) : A(socket) {}
}

Class Ab : public A {
    public:
        typedef boost::shared_ptr<Ab>   pointer;

        static pointer create(tcp::socket& socket) {
            return pointer(new Ab(socket));
        }

    private:
        Ab(&tcp::socket socket) : A(socket) {}
}

[…]

Class Ax : public A {
    public:
        typedef boost::shared_ptr<Ax>   pointer;

        static pointer create(tcp::socket& socket) {
            return pointer(new Ax(socket));
        }

    private:
        Ax(&tcp::socket socket) : A(socket) {}
}

I would like to create a factory pattern using boost::factory
I have writted something like that :

class MyFactory {
    public:
        static MyFactory* getInstance();

        typedef boost::function< A(tcp::socket) > a_fact;

    private:
        MyFactory() {
            map["Aa"] = boost::bind(boost::factory< Aa::create >, _1);
            map["Ab"] = boost::bind(boost::factory< Ab::create >, _1);
            […]
            map["Ax"] = boost::bind(boost::factory< Ax::create >, _1);
        }

        std::map<std::string, a_fact>   map;
    };

And of course, it does not compil…
giving me the error :

MyFactory.cc:13: error: type/value mismatch at argument 1 in template parameter list for ‘template<class Pointer, class Allocator, boost::factory_alloc_propagation AP> class boost::factory’
MyFactory.cc:13: error:   expected a type, got ‘Aa::create’

Any idea, how should I implement it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:31:00+00:00Added an answer on May 22, 2026 at 11:31 am

    If anyone goes into the same mistake, Here the answer.
    It does not need boost::factory to work, using boost::function directly is enough.

    so

    class MyFactory {
        public:
            static MyFactory* getInstance();
    
            typedef boost::function< A(tcp::socket) > a_fact;
    
        private:
            MyFactory() {
                map["Aa"] = boost::bind(&Aa::create, _1);
                map["Ab"] = boost::bind(&Ab::create, _1);
                […]
                map["Ax"] = boost::bind(&Ax::create, _1);
            }
    
            std::map<std::string, a_fact>   map;
        };
    

    Works great !!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple classes that all derive from a base class, now some of
I have multiple Users, each with a collection of Tasks. public class User {
I have a base class that inherits List<> which has multiple classes derived from
Say we have a class inheriting from two base classes (multiple inheritance). Base class
I have a program where I have multiple classes derived from a base class.
I have multiple classes that inherit from one base class, and each class is
I have multiple images that have the same class attribute and I want to
Is it possible to have multiple classes that inherit/extends same class in Google AppEngine
I had a question about Java Class Path variables. If I have multiple jars
I have a java class: it.eng.ancona.view.RuoliView$TabElaborazioneFattureValidazione$ElencoDettaglioElaborazioneFattureValidazione$RigaElencoDettaglioElaborazioneFattureValidazione It's so long for multiple inner class. If

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.