Re: Future of C++
On Aug 7, 7:01 am, Felipe Magno de Almeida
<felipe.m.alme...@gmail.com> wrote:
It is been like two years ago. The code was something like this:
struct base
{
virtual std::type_info& get_type() const = 0;
};
struct derived1
{
std::type_info& get_type() const { return typeid(*this); }
};
struct derived2
{
std::type_info& get_type() const { return typeid(*this); }
};
You have probably meant
struct derived1 : public base { ... }
and possibly
const std::type_info& get_type() const { ... }
Given that, could you explain what exactly is the problem with the
example you have provided above? To me, it looks like a logical thing
to do when you want to discover the derived type and you only have
access to the base pointer or reference. It is usually faster than
dynamic_cast.
I know very well how boost.any works and I don't know
what it has to do with what I wrote.
Here's a snippet from boost::any:
class any
{
....
const std::type_info & type() const
{
return content ? content->type() : typeid(void);
}
....
template<typename ValueType>
class holder : public placeholder
{
....
virtual const std::type_info & type() const
{
return typeid(ValueType);
}
....
};
};
Since OgreAny is a carbon-copy of boost::any, it seems to have a lot
with what you wrote.
See
http://www.ogre3d.org/docs/api/html/OgreAny_8h-source.html
http://svn.boost.org/svn/boost/trunk/boost/any.hpp
Alex
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]