"Gonzalo Aguirre" <> wrote...
> i have three classes like this
>
>
You really need to learn to format your source...
>
> class foo{
> attrib_1;
What is that supposed to be? If it doesn't matter for your
example, just don't write it.
> ..
> ..
> public:
> ..
>
>
> };
>
>
> /************ BAR ***********/
> class bar{
> class foo *f;
You can drop the word 'class' here. Just write
foo *f;
> int position;
> ...
> public:
> foo(int);
> foo & operator[](int);
>
> };
>
> foo:foo(int elem){
> f = new foo[elem];
> ...
> }
>
> foo &
> bar:
perator[](int index){
> // check code omited
> return f[index];
> }
>
>
>
> /************** STACK ***********/
> class stack{
> class bar b; //i use bar as a vector
> int sp; //stack pointer
> public:
> stack();
> foo & pop();
> void push(foo &);
> };
>
> stack::stack{
> b(QUANT); // <--- create a vector of a constant value
What's 'QUANT'? I didn't see it declared anywhere...
> sp = 1;
Why not '0'?
> }
>
> foo &
> stack:
op(){
> // check code omited
> return b[sp];
What happens to 'sp' here? Nothing?
> }
>
>
> void
> stack:
ush(foo & f){
> (2) b[++sp] = f; // <---- operator[] as lvalue ***** (2) *******
So, you never use the values 0 and 1 of 'sp'. Why? Shouldn't this
be
b[sp++] = f;
?
> }
>
>
>
> /************* MAIN *************/
> int
> main(void){
>
> foo f(1,2);
> bar b(5); // <-- vector of 5 elements (see foo:foo(int))
> stack s;
>
> (1) b[1] = f; // <-- which method invoke? ()
What do you mean? The only member function you have here is
the operator[]. It should be invoked.
>
>
> s.push(f); // <-- this try to call operator[]
>
> return 0;
> }
>
> why if i assing in (2) as in (1), or looks like that, they don't call the
> same method??
What do you mean? They should. In the source code you provided
there is nothing else to call.
Perhaps you should read FAQ 5.8.
Victor