On a whim I tested something the other day, which appears to work with
g++ 3.3.4.  Unfortunately it sometimes appears to exhibit flaky
behavior when statically linking... (i.e. mysterious segfault on the
line following the declaration of the array).

class Foo
{
public:
    int x;
    int y;
    int z;
};

void test(int i)
{
    Foo foo[i];

    cout << "sizeof(foo): " << sizeof(foo) << endl;
}

int main()
{
    int i;

    cout << "Val? ";
    cin >> i;

    test(i);

    return 0;
}

In the above program the function "test" will dynamically create an
array "foo" with "i" elements, which gets freed automatically upon exit
of the function.

_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to