All pastes #90693 Raw Edit

Untitled

public text v1 · immutable
#90693 ·published 2006-07-17 22:58 UTC
rendered paste body
class Foo {
    double array[50];

public:
    Foo() {
        for (int i = 0; i < 50; i++) {
            array[i] = sqrt(i * i * 12);
        }
    }
    double operator[](const int index) {
        return array[index];
    }
    double operator[](const char *exp) {
        int index;
        sscanf(exp, ":%d", &index);
        return array[50 - index];
    }
};

int main(void) {
    Foo one;
    printf("operator[](int): %.2lf %.2lf %.2lf\n", one[49], one[48], one[47]);
    printf("operator[](char): %.2lf %.2lf %.2lf\n", one[":1"], one[":2"], one[":
3"]);

    return 0;
}




operator[](int): 169.74 166.28 162.81
operator[](char): 169.74 166.28 162.81