Overview
Examples
Screenshots
Comparisons
Applications
Download
Manual
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
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.

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

 

class TestWindow : public TopWindow

{

};

 

EditString es;

 

GUI_APP_MAIN

{

    TestWindow().Run();

}

Warning: You cannot define widgets as global variable. This is rather host platform dependent technical issue rather than deliberate decision.

 

The code might run OK on some platforms, but crash on others. Means, just do not do it...

 

 

Last edit by cxl on 04/05/2009. Do you want to contribute?. T++