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 3311472
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:52:51+00:00 2026-05-17T21:52:51+00:00

I have the following implementation of a clone_ptr in an attempt to make safe

  • 0

I have the following implementation of a clone_ptr in an attempt to make safe copies of object pointers that need to be copied in a class, so instead of using the copy constructor, I was adviced to use smart pointers and create a clone pointer.

Clone_ptr implementation:

#include <algorithm>
#include <functional>
#include <xercesc/dom/DOM.hpp>

struct DOMImplementation_cloner
{
    template <typename T>
    T* operator()(T* pPtr) const
    {
        /* your clone code*/.
        T = DOMImplementationRegistry::getDOMImplementation(X("Core"));
    }
};

struct default_clone
{
    template <typename T>
    T* operator()(T* pPtr) const
    {
        return pPtr->clone();
    }
};

template <typename T, typename Cloner = default_clone>
    class clone_ptr
    {
    public:
        // types
        typedef T element_type;

        typedef element_type value_type;
        typedef const element_type const_value_type;
        typedef value_type* pointer;
        typedef const_value_type* const_pointer;
        typedef value_type& reference;
        typedef const_value_type& const_reference;

        // creation
        clone_ptr() :
        mPtr(0)
        {}

        explicit clone_ptr(pointer pPtr) :
        mPtr(pPtr)
        {}


        clone_ptr(const clone_ptr& pOther) :
        mPtr(pOther.get() ? mCloner(pOther.get()) : 0)
        {}

      /*  clone_ptr(const clone_ptr& pOther) :
        mPtr(pOther.get() ? pOther->clone() : 0),
        {}*/



        clone_ptr& operator=(clone_ptr pOther)
        {
            swap(*this, pOther);

            return *this;
        }

        ~clone_ptr()
        {
            delete get();
        }

        // observers
        pointer get() const
        {
            return mPtr;
        }

        pointer operator->() const
        {
            return get();
        }

        reference operator*() const
        {
            assert(get() != 0);
            return *get();
        }

        // modifiers
        pointer release()
        {
            pointer result = mPtr;
            mPtr = 0;

            return result;
        }

        void reset(pointer pPtr = 0)
        {
            *this = clone_ptr(pPtr);
        }

        // utility
        friend void swap(clone_ptr& pFirst, clone_ptr& pSecond)
        {
            std::swap(pFirst.mPtr, pSecond.mPtr);
        }


        /////////////////////


    // compare
    template <typename T1, typename T2>
    friend bool operator==(const clone_ptr<T1>& pFirst, const clone_ptr<T2>& pSecond)
    {
        return pFirst.get() == pSecond.get();
    }

    template <typename T1, typename T2>
    friend bool operator!=(const clone_ptr<T1>& pFirst, const clone_ptr<T2>& pSecond)
    {
        return !(pFirst == pSecond);
    }

    template <typename T1, typename T2>
    friend bool operator<(const clone_ptr<T1>& pFirst, const clone_ptr<T2>& pSecond)
    {
        return std::less<void*>()(pFirst.get(), pSecond.get());
    }

    template <typename T1, typename T2>
    friend bool operator<=(const clone_ptr<T1>& pFirst, const clone_ptr<T2>& pSecond)
    {
        return !(pFirst > pSecond);
    }

    template <typename T1, typename T2>
    friend bool operator>(const clone_ptr<T1>& pFirst, const clone_ptr<T2>& pSecond)
    {
        return pSecond < pFirst;
    }

    template <typename T1, typename T2>
    friend bool operator>=(const clone_ptr<T1>& pFirst, const clone_ptr<T2>& pSecond)
    {
        return !(pFirst < pSecond);
    }

    template <typename T1>
    friend bool operator!(const clone_ptr<T1>& pX)
    {
        return pX.get() == 0;
    }


    private:
        pointer mPtr;
        default_clone mCloner;
    };

/// Use of a xerces pointer so it can be copied/cloned safely

 private class member:
        clone_ptr<DOMImplementation, DOMImplementation_cloner> impl;

//compiler error:
 error C2039: 'clone' : is not a member of 'xercesc_3_1::DOMImplementation'

I don’t understand why it is not using the DOMImplementation_cloner and tries to use the default_clone instead?

Can someone clarify as to what I’m doing wrong?

  • 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-17T21:52:51+00:00Added an answer on May 17, 2026 at 9:52 pm

    The type of the cloner is hard-coded to default_clone, instead of using the template parameter Cloner (see the last line of your class definition).

    Edit Just to make sure you understand, your definition of mCloner should look like this:

    Cloner mCloner;
    

    This way the cloner will actually be of the type given by the template parameter.

    One more thing. If you expect you clone_ptr to be used in a more general setting (e.g. by coworkers on other projects), you should make the type of the cloner a property of the type T. This can be done using type traits (this answer gives an example). This could look like this in your clone_ptr:

    template< typename T, typename Cloner = cloner_traits< T >::cloner_type >
    class clone_ptr {
        // ...
    };
    

    This would have the same default behavior as your current implementation. The advantage is that classes that require a special cloner would just specialize the cloner_traits template and the user of the class does not have to worry about choosing the appropriate cloner. If you still want to override the cloner for any class, you can still pass the cloner manually.

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

Sidebar

Related Questions

I have the following code implementation of my generic singleton provider: public sealed class
I have a class that handles serialization in C#, called Serializer. It's implementation is
I have this following codes: @implementation MyImageView @synthesize image; //image is a UIImage -
I have the following own Interface Implementation in my Fragment: @Override public void onReportChanged(Fragment
I have the following scenario.The implementation is required for a real time application. 1)I
I have a problem with the following implementation of hook_cron in Drupal 6.1.3. The
Given I have two File objects I can think of the following implementation: public
I have the following classes/protocols: @interface Super @end @implementation Super @end @interface Sub1 @end
i have the following code, taken partly from a Red Black Tree Java implementation.
I seem to have a error in the following A* pathfinding implementation, which I

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.