Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » [BUG] ArrayMap::Create<TT>: implicit downcast
[BUG] ArrayMap::Create<TT>: implicit downcast [message #34031] Tue, 11 October 2011 20:54
Shire is currently offline  Shire
Messages: 41
Registered: September 2006
Location: Russia, Yamal peninsula
Member
class ArrayMap
...
template <class TT>
TT& Create(const K& k)
{
  TT *q = new TT;
  B::key.Add(k);
  return B::value.Add(q);
}


This template method must create and add some derived object to container of base object pointers.
But B::value.Add() (which is Array<T>::Add()) returns T& and it cannot be downcasted to TT& implicitly.

Test case:
struct A { int a; };
struct B : A { int b; };

ArrayMap<int, A> map;

map.Create<A>(0).a; // ok
map.Create<B>(0).b; // error


Fix: replace last method line with
  return static_cast<TT&>(B::value.Add(q));

Previous Topic: Serialize a VectorMap
Next Topic: Cout() buffering problem
Goto Forum:
  


Current Time: Sun Apr 28 00:26:40 CEST 2024

Total time taken to generate the page: 1.99793 seconds