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

  • SEARCH
  • Home
  • 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 8140581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:12:34+00:00 2026-06-06T12:12:34+00:00

#include <boost/format.hpp> #include <boost/scoped_ptr.hpp> #include <stdexcept> #include <unordered_map> #include <functional> #define DECLARE_OBJECT(classname) namespace {core::declare_object<classname>

  • 0
#include <boost/format.hpp>
#include <boost/scoped_ptr.hpp>
#include <stdexcept>
#include <unordered_map>
#include <functional>
#define DECLARE_OBJECT(classname) namespace {core::declare_object<classname> __declarartion_#classname;}

namespace core {
  class dungeon;
  class object;
  typedef  std::function<object* (dungeon *)> object_creator;
  namespace  library_type {
    enum type {
      landscape = 0, walker, foe, bonus,object = 42
    };
  };
  struct library_error : public std::logic_error 
  {
    explicit library_error(const std::string &what) : std::logic_error(what) {};
  };
  template <enum  library_type::type type>
  class library {
  public:
    static library<type> *instance() {
      if (!m_instance)
        m_instance = new library<type>();
      return m_instance;
    }
    template<typename T>
    void add_object() {
      boost::scoped_ptr<T> obj(T::create(nullptr));
      m_library.insert(obj->name(), T::create);
    }
    const object_creator& get_object(const std::string &key) {
      auto lookup_iterator = m_library.find(key);
      if (lookup_iterator == m_library.end())
        throw library_error(boost::format("Object creator for key `%1%' not found\n") % key);
      return *lookup_iterator;
    }
  private:
    library () {};
    static library<type> *m_instance;
    std::unordered_map<std::string, object_creator> m_library;
  };
  template <enum library_type::type type>
  library<type>*  library<type>::m_instance;
  template <enum  library_type::type type, typename T>
  struct declare_object
  {
    declare_object() {
      auto instance = library<type>::instance();
      auto method = instance->add_object<T>;
      method();
    }
  };
};
int main()
{

}

Hello. This simple C++0x code gives me error in declare_object constructor

example.cpp: In constructor ‘core::declare_object<type, T>::declare_object()’:
example.cpp:52:43: error: expected primary-expression before ‘>’ token
example.cpp:52:44: error: expected primary-expression before ‘;’ token

I have really no idea where I am wrong. Maybe clear view and suggestions?
Sorry for long listing.
EDIT: Answer was auto method = instance -> template add_object<T>;. Why you deleted your answer?

  • 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-06-06T12:12:37+00:00Added an answer on June 6, 2026 at 12:12 pm

    To get a pointer to member function you need to follow the syntax in the other answer.

    Since the member function is furthermore a template, you need to indicate this because it’s a dependent name:

    auto method = &library_type<type>::template add_object<T>;
    

    Otherwise C++ will parse the pointy braces in add_object<T> as less-than and greater-than operators.

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

Sidebar

Related Questions

Why won't this compile? #include <functional> #include <boost/function.hpp> class A { A() { typedef
I have a object cache class like this: #include boost/thread/mutex.hpp #include boost/unordered_map.hpp template <typename
I have the following code: #include <iostream> #include boost/unordered_map.hpp using namespace std; using namespace
Please consider the following simplified example: #include boost/shared_ptr.hpp #include boost/smart_ptr/enable_shared_from_this.hpp using namespace boost; class
Consider the following : #include <vector> #include <string> #include <iostream> #include <boost/format.hpp> #include <boost/assign.hpp>
I have the following code: #include <iostream> #include boost/shared_ptr.hpp using boost::shared_ptr; class Base {
#include <boost/smart_ptr.hpp> class Base { }; class Derived : public Base { public: Derived()
#include <boost/ptr_container/ptr_vector.hpp> #include <iostream> using namespace std; using namespace boost; struct A { ~A()
#include <boost/algorithm/string.hpp> #include <vector> #include <iostream> #include <string> using namespace std; using namespace boost;
This code: #include <boost/signals.hpp> #include <boost/bind.hpp> #include <boost/mem_fn.hpp> #include <iostream> class Recorder : public

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.