Overview
Examples
Screenshots
Comparisons
Applications
Download
Manual
Status & Roadmap
FAQ
Authors & License
Forums
Wiki
Funding Ultimate++
Search on this site









SourceForge.net Logo



U++ traps and pitfalls

 

Vector<Foo> x;

....

x.At(i) = x[q];

Problem: At invalidates references to Vector; if x[q] gets evaluated first, the reference can be later invalidated by At. (Note: Array does not have the same problem).

Vector<Foo> x;

....

const Foo& s = x.Top();

x.Add() = s;

....

x.Add(x.Top());

....

x.Add(x[0]);

Very similar to above problem, only more explicit.

void MyFn(Array<Foo> x);

This is in most cases a bug - U++ containers have "pick transfer semantics", means that such function destroys the real parameter. (Rarely, however, this can be on purpose).

int x = Null;

double y = x;

C++ knows nothing about U++ Null concept, y will not be a Null. Note that Value is aware about the Null, so this code:

 

int x = Null;

Value v = x;

double y = v;

 

behaves as expected.