Topic: Why no copy constructor in 'type_info


Author: Erez Bashan <erez@tecnomatix.com>
Date: 1997/04/15
Raw View
Why there is no (public) copy constructor in the RTTI class 'type_info'
?
A lot of third party and standard tools can't work with 'type_info'
because of that.

Anyway, what do you think is the best way to overcome this ?

Thanks

Erez Bashan,
Tecnomatix Technologies LTD.
Delta House, 16 Hagalim Avenue,
Herzeliya 46733, Israel
Tel: +972-9-594777 Fax: +972-9-544402
Email: erez@tecnomatix.com

      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Gerard Weatherby <gerardw@alum.mit.edu>
Date: 1997/04/15
Raw View
Erez Bashan wrote:
>
> Why there is no (public) copy constructor in the RTTI class 'type_info'
> ?
> A lot of third party and standard tools can't work with 'type_info'
> because of that.
>
> Anyway, what do you think is the best way to overcome this ?

Can't work is a pretty strong phrase to use!  Below is an example of
storing types in a RogueWave (no, I don't work for them) RWTValSlist.

(It's undoubtedly the worst object oriented design ever conceived, is
not compliant with the standard, leaks memory, poorly documented, should
use the auto_ptr, etc. etc.)
#include <typeinfo.h>
#include <rw/tvslist.h>
#include <iostream.h>

class TypeHolder {
 public:
  TypeHolder(const typeinfo &t)
   :tinfo(t) {}
  TypeHolder(const TypeHolder &rhs)
   :tinfo(rhs.tinfo) {}
  const typeinfo & GetType( ) { return tinfo; }
 private:
  const typeinfo & tinfo;
};

bool operator==(const TypeHolder &lhs, const TypeHolder &rhs)
{
 return lhs == rhs;
}

class ValHolder {
 public:
  ValHolder(const typeinfo &t)
   :pType(new TypeHolder(t)) { }
  ValHolder(const TypeHolder &rhs)
   :pType(new TypeHolder(rhs)) { }
  ValHolder(const ValHolder &rhs)
   :pType(new TypeHolder(*rhs.pType)) { }
  ~ValHolder( ) { delete pType; }
  const typeinfo & GetType( ) { return pType->GetType( ); }
  ValHolder & operator=(const ValHolder &rhs)
   { delete pType;
     pType = new TypeHolder(*rhs.pType);
     return *this; }
 private:
  TypeHolder* pType;
};

bool operator==(const ValHolder &lhs, const ValHolder &rhs)
{
 return lhs.GetType( ) == rhs.GetType( );
}

int main( )
{
 RWTValSlist<ValHolder> listOfTypes;
 listOfTypes.append(typeid(int));
 listOfTypes.append(typeid(char));
 long aVariable;
 listOfTypes.append(typeid(aVariable));
 RWTValSlistIterator<ValHolder> iter(listOfTypes);
 while (iter( ))
  {
  ValHolder holder = iter.key( );
  cout << holder.GetType( ).name( ) <<  endl;
  }
}
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]