Re: compile error on constructor/private
 
On 8/10/2011 2:13 PM, eric wrote:
Dear C/g++ experts:
I declare the following
--------------------------------------------------------
     template<typename T>
   class DOMPtr {
   public:
       DOMPtr(T* t) : t_(t) { }
       ~DOMPtr() { t_->release(); }
       T* operator->() const { return t_; }
   private:
       // prohibit copying and assigning
       DOMPtr(const DOMPtr&);                    // this is my line 38
       DOMPtr&  operator=(const DOMPtr&);
       T* t_;
   };
-------------------------------------------------------------------------------
then use it here
----------------------------------------------------------
         DOMPtr<DOMBuilder>  parser =
             static_cast<DOMImplementationLS*>        // this is 94
(impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
-------------------
         // Construct a DOMWriter to save animals.xml
         DOMPtr<DOMWriter>  writer =
             static_cast<DOMImplementationLS*>(impl)-
createDOMWriter(); // this 140
This is conceptually equivalent to:
     DOMPtr<DOMWriter> writer =
         DOMPtr<DomWriter>(static_cast ...);
The compiler elides the assignment, but it still needs to be
visible.  And your assignment operator is private.
Try rewriting line 94 and 140 as direct constructor calls:
      DOMPtr<DOMBuilder> parser(static_cast ...); // 94
      DOMPtr<DOMWriter> writer(static_cast ...);  // 140